From a33ce3f69921742e30f7ba6fd0d2139de689b2d4 Mon Sep 17 00:00:00 2001 From: Jessica Lynn Suttles Date: Mon, 18 Feb 2013 09:30:12 -0800 Subject: [PATCH] renames Property::Foundation#value to #to_s --- lib/microformats2/property/date_time.rb | 14 +++++------ lib/microformats2/property/embedded.rb | 4 +-- lib/microformats2/property/foundation.rb | 10 ++++---- spec/lib/microformats2/collection_spec.rb | 30 +++++++++++------------ 4 files changed, 28 insertions(+), 30 deletions(-) diff --git a/lib/microformats2/property/date_time.rb b/lib/microformats2/property/date_time.rb index c95576e..48b3ba2 100644 --- a/lib/microformats2/property/date_time.rb +++ b/lib/microformats2/property/date_time.rb @@ -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 diff --git a/lib/microformats2/property/embedded.rb b/lib/microformats2/property/embedded.rb index 77d4785..58de6cc 100644 --- a/lib/microformats2/property/embedded.rb +++ b/lib/microformats2/property/embedded.rb @@ -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 diff --git a/lib/microformats2/property/foundation.rb b/lib/microformats2/property/foundation.rb index 71f37f7..3ab0cf0 100644 --- a/lib/microformats2/property/foundation.rb +++ b/lib/microformats2/property/foundation.rb @@ -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 diff --git a/spec/lib/microformats2/collection_spec.rb b/spec/lib/microformats2/collection_spec.rb index 1fe6385..460ad22 100644 --- a/spec/lib/microformats2/collection_spec.rb +++ b/spec/lib/microformats2/collection_spec.rb @@ -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 == "

Vegan. Cat lover. Coder.

" + it "assigns inner_text to Property#to_s" do + @collection.first.content.first.to_s.should == "

Vegan. Cat lover. Coder.

" 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