cleans up implied properties and fixes spec

This commit is contained in:
Jessica Lynn Suttles 2013-02-14 14:02:29 -08:00
parent 10ea0256fc
commit 7385f09eaf
3 changed files with 13 additions and 19 deletions

View file

@ -1,7 +1,6 @@
module Microformats2 module Microformats2
module ImpliedProperty module ImpliedProperty
class Foundation class Foundation
attr_reader :selector
def initialize(element) def initialize(element)
@element = element @element = element
@ -30,33 +29,28 @@ module Microformats2
protected protected
def element_value def element_value
ev = nil
name_map.each_pair do |elname, attr| name_map.each_pair do |elname, attr|
if elname == @element.name && @element.attribute(attr) if elname == @element.name && @element.attribute(attr)
ev ||= @element.attribute(attr).to_s return @element.attribute(attr).to_s
@selector ||= elname
end end
end end
ev nil
end
def name_map
{}
end end
def selector_value def selector_value
sv = nil
selector_map.each_pair do |sel, attr| selector_map.each_pair do |sel, attr|
selected_elements = @element.css(sel) if selected_element = @element.css(sel).first
if selected_elements.first return selected_element.attribute(attr).to_s
sv ||= selected_elements.first.attribute(attr).to_s
@selector ||= sel
end end
end end
sv nil
end end
def attribute def selector_map
attr_map[@element.name]
end
def attr_map
{} {}
end end
end end

View file

@ -21,13 +21,12 @@ module Microformats2
{ ">img[alt]:only-of-type" => "alt", { ">img[alt]:only-of-type" => "alt",
">abbr[title]:only-of-type" => "title", ">abbr[title]:only-of-type" => "title",
">:only-of-type>img[alt]:only-of-type" => "alt", ">:only-of-type>img[alt]:only-of-type" => "alt",
">:only-of-type>abbr[title]:only-of-type" => "title" } # only-of-type bit not working ">:only-of-type>abbr[title]:only-of-type" => "title" }
end end
private private
def text_value def text_value
@selector = "inner_text"
@element.inner_text.gsub(/\n+/, " ").gsub(/\s+/, " ").strip @element.inner_text.gsub(/\n+/, " ").gsub(/\s+/, " ").strip
end end
end end

View file

@ -93,7 +93,8 @@ describe Microformats2::Collection do
:url => ["http://twitter.com/jlsuttles"], :url => ["http://twitter.com/jlsuttles"],
:name => ["Jessica Lynn Suttles"] :name => ["Jessica Lynn Suttles"]
} }
}] }],
:name => ["Jessica Lynn Suttles"]
} }
}] }]
} }