Class: Microformat::AttributeMap
- Inherits:
-
Object
- Object
- Microformat::AttributeMap
- Defined in:
- lib/microformat/attribute_map.rb
Instance Attribute Summary collapse
-
#definition ⇒ Object
readonly
Returns the value of attribute definition.
-
#document ⇒ Object
readonly
Returns the value of attribute document.
Instance Method Summary collapse
-
#initialize(definition, document, values = {}) ⇒ AttributeMap
constructor
A new instance of AttributeMap.
- #method_missing(name, *args, &block) ⇒ Object
- #respond_to_missing?(name, public_only = false) ⇒ Boolean
Constructor Details
#initialize(definition, document, values = {}) ⇒ AttributeMap
Returns a new instance of AttributeMap.
5 6 7 8 9 10 |
# File 'lib/microformat/attribute_map.rb', line 5 def initialize(definition, document, values = {}) @definition = definition @document = document @values = values @attribute_cache = {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/microformat/attribute_map.rb', line 17 def method_missing(name, *args, &block) if values_responds_to?(name) @values.fetch(name.to_sym) elsif @attribute_cache.has_key?(name) @attribute_cache[name] elsif definition_responds_to?(name) attribute = @definition.attributes.fetch(name) value = attribute.read_from(document) @attribute_cache[name] = value else super(name) end end |
Instance Attribute Details
#definition ⇒ Object (readonly)
Returns the value of attribute definition.
3 4 5 |
# File 'lib/microformat/attribute_map.rb', line 3 def definition @definition end |
#document ⇒ Object (readonly)
Returns the value of attribute document.
3 4 5 |
# File 'lib/microformat/attribute_map.rb', line 3 def document @document end |
Instance Method Details
#respond_to_missing?(name, public_only = false) ⇒ Boolean
12 13 14 15 |
# File 'lib/microformat/attribute_map.rb', line 12 def respond_to_missing?(name, public_only = false) values_responds_to?(name) || definition_responds_to?(name) end |