From 7385f09eaf98a8ba75489c6b0514ad5b5f0ed17c Mon Sep 17 00:00:00 2001 From: Jessica Lynn Suttles Date: Thu, 14 Feb 2013 14:02:29 -0800 Subject: [PATCH] cleans up implied properties and fixes spec --- .../implied_property/foundation.rb | 26 +++++++------------ lib/microformats2/implied_property/name.rb | 3 +-- spec/lib/microformats2/collection_spec.rb | 3 ++- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/lib/microformats2/implied_property/foundation.rb b/lib/microformats2/implied_property/foundation.rb index ab49af9..6797d6c 100644 --- a/lib/microformats2/implied_property/foundation.rb +++ b/lib/microformats2/implied_property/foundation.rb @@ -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 diff --git a/lib/microformats2/implied_property/name.rb b/lib/microformats2/implied_property/name.rb index 766c7d6..ac5e508 100644 --- a/lib/microformats2/implied_property/name.rb +++ b/lib/microformats2/implied_property/name.rb @@ -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 diff --git a/spec/lib/microformats2/collection_spec.rb b/spec/lib/microformats2/collection_spec.rb index a8c9419..d07f918 100644 --- a/spec/lib/microformats2/collection_spec.rb +++ b/spec/lib/microformats2/collection_spec.rb @@ -93,7 +93,8 @@ describe Microformats2::Collection do :url => ["http://twitter.com/jlsuttles"], :name => ["Jessica Lynn Suttles"] } - }] + }], + :name => ["Jessica Lynn Suttles"] } }] }