renames Property::Foundation#value to #to_s

This commit is contained in:
Jessica Lynn Suttles 2013-02-18 09:30:12 -08:00
parent f78e158b7c
commit a33ce3f699
4 changed files with 28 additions and 30 deletions

View file

@ -1,21 +1,19 @@
module Microformats2
module Property
class DateTime < Foundation
def value
::DateTime.parse(string_value)
rescue ArgumentError => e
string_value
def to_s
@to_s ||= value_class_pattern || element_value || text_value
end
def string_value
@string_value ||= value_class_pattern || element_value || text_value
def value
::DateTime.parse(to_s)
end
def to_hash
if formats.empty?
string_value.to_s
to_s
else
{ value: string_value.to_s }.merge(formats.first.to_hash)
{ value: to_s }.merge(formats.first.to_hash)
end
end

View file

@ -1,8 +1,8 @@
module Microformats2
module Property
class Embedded < Foundation
def value
@value ||= @element.inner_html.strip
def to_s
@to_s ||= @element.inner_html.strip
end
end
end

View file

@ -9,13 +9,13 @@ module Microformats2
end
def parse
value
to_s
formats
self
end
def value
@value ||= value_class_pattern || element_value || text_value
def to_s
@to_s ||= value_class_pattern || element_value || text_value
end
def formats
@ -24,9 +24,9 @@ module Microformats2
def to_hash
if formats.empty?
value.to_s
to_s
else
{ value: value.to_s }.merge(formats.first.to_hash)
{ value: to_s }.merge(formats.first.to_hash)
end
end

View file

@ -25,27 +25,27 @@ describe Microformats2::Collection do
it "assigns Property from '.h-card .p-name' to HCard#name[]" do
@collection.first.name.first.should be_kind_of Microformats2::Property::Text
end
it "assigns inner_text to Property#value" do
@collection.first.name.first.value.should == "Jessica Lynn Suttles"
it "assigns inner_text to Property#to_s" do
@collection.first.name.first.to_s.should == "Jessica Lynn Suttles"
end
end
describe "HCard#url parsed from '.h-card .p-url'" do
it "assigns Property from '.h-card .p-url' to HCard#url[]" do
@collection.first.url.first.should be_kind_of Microformats2::Property::Url
end
it "assigns inner_text to Property#value" do
it "assigns inner_text to Property#to_s" do
urls = ["http://flickr.com/jlsuttles", "http://twitter.com/jlsuttles"]
@collection.first.url.map(&:value).should == urls
@collection.first.url.map(&:to_s).should == urls
end
end
describe "HCard#bday parsed from '.h-card .p-bday'" do
it "assigns Property from '.h-card .p-bday' to HCard#bday[]" do
@collection.first.bday.first.should be_kind_of Microformats2::Property::DateTime
end
it "assigns datetime attribute to Property#string_value" do
@collection.first.bday.first.string_value.should == "1990-10-15"
it "assigns datetime attribute to Property#string_to_s" do
@collection.first.bday.first.to_s.should == "1990-10-15"
end
it "assigns DateTime object to Property#value" do
it "assigns DateTime object to Property#to_s" do
@collection.first.bday.first.value.should be_kind_of DateTime
@collection.first.bday.first.value.to_s.should == "1990-10-15T00:00:00+00:00"
end
@ -54,8 +54,8 @@ describe Microformats2::Collection do
it "assigns Property from '.h-card .p-content' to HCard#content[]" do
@collection.first.content.first.should be_kind_of Microformats2::Property::Embedded
end
it "assigns inner_text to Property#value" do
@collection.first.content.first.value.should == "<p>Vegan. Cat lover. Coder.</p>"
it "assigns inner_text to Property#to_s" do
@collection.first.content.first.to_s.should == "<p>Vegan. Cat lover. Coder.</p>"
end
end
end
@ -81,16 +81,16 @@ describe Microformats2::Collection do
it "assigns Property from '.h-card .p-name' to HCard#name[]" do
@collection.first.name.first.should be_kind_of Microformats2::Property::Text
end
it "assigns inner_text to Property#value" do
@collection.first.name.first.value.should == "jlsuttles"
it "assigns inner_text to Property#to_s" do
@collection.first.name.first.to_s.should == "jlsuttles"
end
end
describe "HCard#nickname parsed from '.h-card .p-name .p-nickname'" do
it "assigns Property from '.h-card .p-nickname' to HCard#nickname[]" do
@collection.first.nickname.first.should be_kind_of Microformats2::Property::Text
end
it "assigns inner_text to Property#value" do
@collection.first.nickname.first.value.should == "jlsuttles"
it "assigns inner_text to Property#to_s" do
@collection.first.nickname.first.to_s.should == "jlsuttles"
end
end
end
@ -116,8 +116,8 @@ describe Microformats2::Collection do
it "assigns Property to HEntry#author[]" do
@collection.first.author.first.should be_kind_of Microformats2::Property::Text
end
it "assigns inner_text to Property#value" do
@collection.first.author.first.value.should == "Jessica Lynn Suttles"
it "assigns inner_text to Property#to_s" do
@collection.first.author.first.to_s.should == "Jessica Lynn Suttles"
end
it "assigns HCard to Property#formats[]" do
@collection.first.author.first.formats.first.should be_kind_of HCard