Sha256: f90829b368c310e950af9913d0130b358fce929619c23fa77e28add94470184a

Contents?: true

Size: 749 Bytes

Versions: 3

Compression:

Stored size: 749 Bytes

Contents

#coding: utf-8

module Wombat
  module PropertyLocator
    def locate metadata
      metadata.all_properties.each do |p|
        p.result = locate_property(p).first
      end
    end

    private 
    def locate_property property
      result = locate_selector(property.selector, property.namespaces)
      result.map! {|r| r.inner_html.strip } if property.format == :html
      result.map {|r| r.kind_of?(String) ? r : r.inner_text }.map(&:strip)
    end

    def locate_selector selector, namespaces = nil
      return [selector.to_s] if selector.is_a? Symbol
      return context.xpath selector[6..-1], namespaces if selector.start_with? "xpath="
      return context.css selector[4..-1] if selector.start_with? "css="
      nil
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
wombat-0.1.5 lib/wombat/property_locator.rb
wombat-0.1.4 lib/wombat/property_locator.rb
wombat-0.1.3 lib/wombat/property_locator.rb