Class: Zelda::Base
- Inherits:
-
Object
- Object
- Zelda::Base
- Defined in:
- lib/zelda/base.rb
Overview
Abstract base class to provide common functionality of Zelda importer classes. including method_missing magic to turn an @attributes hash into getters.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ Base
constructor
A new instance of Base.
-
#method_missing(method, *args, &block) ⇒ Object
Try both string keys and symbol keys in that order.
Constructor Details
#initialize(attributes = {}) ⇒ Base
Returns a new instance of Base.
5 6 7 8 9 10 11 |
# File 'lib/zelda/base.rb', line 5 def initialize(attributes={}) @attributes = {} attributes.each do |key, value| @attributes[key.to_sym] = value end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
Try both string keys and symbol keys in that order.
16 17 18 19 20 21 22 23 24 |
# File 'lib/zelda/base.rb', line 16 def method_missing(method, *args, &block) if @attributes[method] return @attributes[method] elsif @attributes.key?(method) return nil else super(method, *args, &block) end end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
13 14 15 |
# File 'lib/zelda/base.rb', line 13 def attributes @attributes end |