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

View file

@ -21,13 +21,12 @@ module Microformats2
{ ">img[alt]:only-of-type" => "alt",
">abbr[title]:only-of-type" => "title",
">: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
private
def text_value
@selector = "inner_text"
@element.inner_text.gsub(/\n+/, " ").gsub(/\s+/, " ").strip
end
end

View file

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