Sha256: d5256d4fbbf37187ab1eca39dd729e3a23922b43e9bc1e38c7c4423e6df6da9a

Contents?: true

Size: 1.02 KB

Versions: 7

Compression:

Stored size: 1.02 KB

Contents

require "microformat/attribute_definition"
require "microformat/selectors"

module Microformat
  class Format
    def self.selector(selector = nil)
      define_selector(selector) if selector
      @selector
    end
    
    def self.attribute_definition(&block)
      @attribute_definition = AttributeDefinition.new(&block) if block_given?
      @attribute_definition
    end

    def self.parse(document)
      new(document)
    end
    
    attr_reader :document
    
    def initialize(document)
      @document = document
    end
    
    def respond_to_missing?(name, public_only = false)
      attribute_map.respond_to?(name)
    end

    def method_missing(name)
      if attribute_map.respond_to?(name)
        attribute_map.send(name)
      else
        super(name)
      end
    end
    
    private
    def attribute_map
      @attribute_map ||= self.class.attribute_definition.map_to(document)
    end
    
    def self.define_selector(selector)
      Selectors.define(selector, self)
      @selector = selector
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
elcamino-microformat-0.0.8 lib/microformat/format.rb
microformat-0.0.7 lib/microformat/format.rb
microformat-0.0.6 lib/microformat/format.rb
microformat-0.0.5 lib/microformat/format.rb
microformat-0.0.4 lib/microformat/format.rb
microformat-0.0.3 lib/microformat/format.rb
microformat-0.0.2 lib/microformat/format.rb