renames Property::Foundation#value to #to_s
This commit is contained in:
parent
f78e158b7c
commit
a33ce3f699
4 changed files with 28 additions and 30 deletions
|
@ -1,21 +1,19 @@
|
||||||
module Microformats2
|
module Microformats2
|
||||||
module Property
|
module Property
|
||||||
class DateTime < Foundation
|
class DateTime < Foundation
|
||||||
def value
|
def to_s
|
||||||
::DateTime.parse(string_value)
|
@to_s ||= value_class_pattern || element_value || text_value
|
||||||
rescue ArgumentError => e
|
|
||||||
string_value
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def string_value
|
def value
|
||||||
@string_value ||= value_class_pattern || element_value || text_value
|
::DateTime.parse(to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_hash
|
def to_hash
|
||||||
if formats.empty?
|
if formats.empty?
|
||||||
string_value.to_s
|
to_s
|
||||||
else
|
else
|
||||||
{ value: string_value.to_s }.merge(formats.first.to_hash)
|
{ value: to_s }.merge(formats.first.to_hash)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
module Microformats2
|
module Microformats2
|
||||||
module Property
|
module Property
|
||||||
class Embedded < Foundation
|
class Embedded < Foundation
|
||||||
def value
|
def to_s
|
||||||
@value ||= @element.inner_html.strip
|
@to_s ||= @element.inner_html.strip
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,13 +9,13 @@ module Microformats2
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse
|
def parse
|
||||||
value
|
to_s
|
||||||
formats
|
formats
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
def value
|
def to_s
|
||||||
@value ||= value_class_pattern || element_value || text_value
|
@to_s ||= value_class_pattern || element_value || text_value
|
||||||
end
|
end
|
||||||
|
|
||||||
def formats
|
def formats
|
||||||
|
@ -24,9 +24,9 @@ module Microformats2
|
||||||
|
|
||||||
def to_hash
|
def to_hash
|
||||||
if formats.empty?
|
if formats.empty?
|
||||||
value.to_s
|
to_s
|
||||||
else
|
else
|
||||||
{ value: value.to_s }.merge(formats.first.to_hash)
|
{ value: to_s }.merge(formats.first.to_hash)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -25,27 +25,27 @@ describe Microformats2::Collection do
|
||||||
it "assigns Property from '.h-card .p-name' to HCard#name[]" do
|
it "assigns Property from '.h-card .p-name' to HCard#name[]" do
|
||||||
@collection.first.name.first.should be_kind_of Microformats2::Property::Text
|
@collection.first.name.first.should be_kind_of Microformats2::Property::Text
|
||||||
end
|
end
|
||||||
it "assigns inner_text to Property#value" do
|
it "assigns inner_text to Property#to_s" do
|
||||||
@collection.first.name.first.value.should == "Jessica Lynn Suttles"
|
@collection.first.name.first.to_s.should == "Jessica Lynn Suttles"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
describe "HCard#url parsed from '.h-card .p-url'" do
|
describe "HCard#url parsed from '.h-card .p-url'" do
|
||||||
it "assigns Property from '.h-card .p-url' to HCard#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
|
@collection.first.url.first.should be_kind_of Microformats2::Property::Url
|
||||||
end
|
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"]
|
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
|
||||||
end
|
end
|
||||||
describe "HCard#bday parsed from '.h-card .p-bday'" do
|
describe "HCard#bday parsed from '.h-card .p-bday'" do
|
||||||
it "assigns Property from '.h-card .p-bday' to HCard#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
|
@collection.first.bday.first.should be_kind_of Microformats2::Property::DateTime
|
||||||
end
|
end
|
||||||
it "assigns datetime attribute to Property#string_value" do
|
it "assigns datetime attribute to Property#string_to_s" do
|
||||||
@collection.first.bday.first.string_value.should == "1990-10-15"
|
@collection.first.bday.first.to_s.should == "1990-10-15"
|
||||||
end
|
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.should be_kind_of DateTime
|
||||||
@collection.first.bday.first.value.to_s.should == "1990-10-15T00:00:00+00:00"
|
@collection.first.bday.first.value.to_s.should == "1990-10-15T00:00:00+00:00"
|
||||||
end
|
end
|
||||||
|
@ -54,8 +54,8 @@ describe Microformats2::Collection do
|
||||||
it "assigns Property from '.h-card .p-content' to HCard#content[]" do
|
it "assigns Property from '.h-card .p-content' to HCard#content[]" do
|
||||||
@collection.first.content.first.should be_kind_of Microformats2::Property::Embedded
|
@collection.first.content.first.should be_kind_of Microformats2::Property::Embedded
|
||||||
end
|
end
|
||||||
it "assigns inner_text to Property#value" do
|
it "assigns inner_text to Property#to_s" do
|
||||||
@collection.first.content.first.value.should == "<p>Vegan. Cat lover. Coder.</p>"
|
@collection.first.content.first.to_s.should == "<p>Vegan. Cat lover. Coder.</p>"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -81,16 +81,16 @@ describe Microformats2::Collection do
|
||||||
it "assigns Property from '.h-card .p-name' to HCard#name[]" do
|
it "assigns Property from '.h-card .p-name' to HCard#name[]" do
|
||||||
@collection.first.name.first.should be_kind_of Microformats2::Property::Text
|
@collection.first.name.first.should be_kind_of Microformats2::Property::Text
|
||||||
end
|
end
|
||||||
it "assigns inner_text to Property#value" do
|
it "assigns inner_text to Property#to_s" do
|
||||||
@collection.first.name.first.value.should == "jlsuttles"
|
@collection.first.name.first.to_s.should == "jlsuttles"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
describe "HCard#nickname parsed from '.h-card .p-name .p-nickname'" do
|
describe "HCard#nickname parsed from '.h-card .p-name .p-nickname'" do
|
||||||
it "assigns Property from '.h-card .p-nickname' to HCard#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
|
@collection.first.nickname.first.should be_kind_of Microformats2::Property::Text
|
||||||
end
|
end
|
||||||
it "assigns inner_text to Property#value" do
|
it "assigns inner_text to Property#to_s" do
|
||||||
@collection.first.nickname.first.value.should == "jlsuttles"
|
@collection.first.nickname.first.to_s.should == "jlsuttles"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -116,8 +116,8 @@ describe Microformats2::Collection do
|
||||||
it "assigns Property to HEntry#author[]" do
|
it "assigns Property to HEntry#author[]" do
|
||||||
@collection.first.author.first.should be_kind_of Microformats2::Property::Text
|
@collection.first.author.first.should be_kind_of Microformats2::Property::Text
|
||||||
end
|
end
|
||||||
it "assigns inner_text to Property#value" do
|
it "assigns inner_text to Property#to_s" do
|
||||||
@collection.first.author.first.value.should == "Jessica Lynn Suttles"
|
@collection.first.author.first.to_s.should == "Jessica Lynn Suttles"
|
||||||
end
|
end
|
||||||
it "assigns HCard to Property#formats[]" do
|
it "assigns HCard to Property#formats[]" do
|
||||||
@collection.first.author.first.formats.first.should be_kind_of HCard
|
@collection.first.author.first.formats.first.should be_kind_of HCard
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue