Class: Leafy::FieldValue
- Inherits:
-
Object
- Object
- Leafy::FieldValue
- Defined in:
- lib/leafy/field_value.rb
Instance Attribute Summary collapse
-
#converter ⇒ Object
Returns the value of attribute converter.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#raw ⇒ Object
Returns the value of attribute raw.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(attributes) ⇒ FieldValue
constructor
A new instance of FieldValue.
- #value ⇒ Object
- #value=(val) ⇒ Object
Constructor Details
#initialize(attributes) ⇒ FieldValue
Returns a new instance of FieldValue.
7 8 9 10 11 12 13 14 15 |
# File 'lib/leafy/field_value.rb', line 7 def initialize(attributes) attributes = attributes.dup.to_a.map { |pair| [pair[0].to_sym, pair[1]]}.to_h self.id = attributes.fetch(:id) self.name = attributes.fetch(:name) self.type = attributes.fetch(:type) self.converter = attributes.fetch(:converter) { Leafy.converters.fetch(type.to_sym) { raise(RuntimeError, "unregistered converter #{type}") } } self.raw = attributes.fetch(:raw) end |
Instance Attribute Details
#converter ⇒ Object
Returns the value of attribute converter.
5 6 7 |
# File 'lib/leafy/field_value.rb', line 5 def converter @converter end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/leafy/field_value.rb', line 5 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/leafy/field_value.rb', line 5 def name @name end |
#raw ⇒ Object
Returns the value of attribute raw.
5 6 7 |
# File 'lib/leafy/field_value.rb', line 5 def raw @raw end |
#type ⇒ Object
Returns the value of attribute type.
5 6 7 |
# File 'lib/leafy/field_value.rb', line 5 def type @type end |
Instance Method Details
#value ⇒ Object
17 18 19 |
# File 'lib/leafy/field_value.rb', line 17 def value converter.load(raw) end |
#value=(val) ⇒ Object
21 22 23 |
# File 'lib/leafy/field_value.rb', line 21 def value=(val) self.raw = converter.dump(converter.load(val)) end |