Sha256: cc1900f17b5f0e798a7c0178c6030282e32691c67874b291fd78f053237f9233

Contents?: true

Size: 994 Bytes

Versions: 5

Compression:

Stored size: 994 Bytes

Contents

module Microformats2
  module ImpliedProperty
    class Foundation

      def initialize(element)
        @element = element
      end

      def parse
        self if to_s
      end

      def method_name
        "foundation"
      end

      def to_s
        @to_s ||= element_value || selector_value
      end

      def to_hash
        to_s
      end

      def to_json
        to_hash.to_json
      end

      protected

      def element_value
        name_map.each_pair do |elname, attr|
          if elname == @element.name && @element.attribute(attr)
            return @element.attribute(attr).to_s
          end
        end
        nil
      end

      def name_map
        {}
      end

      def selector_value
        selector_map.each_pair do |sel, attr|
          if selected_element = @element.css(sel).first
            return selected_element.attribute(attr).to_s
          end
        end
        nil
      end

      def selector_map
        {}
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
microformats2-2.0.0.pre5 lib/microformats2/implied_property/foundation.rb
microformats2-2.0.0.pre4 lib/microformats2/implied_property/foundation.rb
microformats2-2.0.0.pre3 lib/microformats2/implied_property/foundation.rb
microformats2-2.0.0.pre2 lib/microformats2/implied_property/foundation.rb
microformats2-2.0.0.pre1 lib/microformats2/implied_property/foundation.rb