Class: Oym::Attribute
- Inherits:
-
Object
- Object
- Oym::Attribute
- Defined in:
- lib/oym/attribute.rb
Instance Attribute Summary collapse
-
#array ⇒ Object
Returns the value of attribute array.
-
#klass ⇒ Object
Returns the value of attribute klass.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(name, klass, array) ⇒ Attribute
constructor
A new instance of Attribute.
- #key ⇒ Object
- #value_from(data) ⇒ Object
Constructor Details
#initialize(name, klass, array) ⇒ Attribute
Returns a new instance of Attribute.
7 8 9 10 11 |
# File 'lib/oym/attribute.rb', line 7 def initialize(name, klass, array) @name = name @klass = klass @array = array end |
Instance Attribute Details
#array ⇒ Object
Returns the value of attribute array.
5 6 7 |
# File 'lib/oym/attribute.rb', line 5 def array @array end |
#klass ⇒ Object
Returns the value of attribute klass.
4 5 6 |
# File 'lib/oym/attribute.rb', line 4 def klass @klass end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/oym/attribute.rb', line 3 def name @name end |
Instance Method Details
#key ⇒ Object
13 14 15 |
# File 'lib/oym/attribute.rb', line 13 def key "#{@name}=" end |
#value_from(data) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/oym/attribute.rb', line 17 def value_from(data) raw = data[name.to_s] return raw unless klass unless klass.respond_to?(:from_data) raise "#{klass} is specified as Oym::Attribute's klass, but #{klass} does not respond to from_data" end array ? raw.map { |e| klass.from_data(e) } : klass.from_data(raw) end |