Class: Leafy::Field
- Inherits:
-
Object
- Object
- Leafy::Field
- Defined in:
- lib/leafy/field.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#name ⇒ Object
Returns the value of attribute name.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ Field
constructor
A new instance of Field.
- #serializable_hash ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Field
Returns a new instance of Field.
8 9 10 11 12 13 14 15 16 |
# File 'lib/leafy/field.rb', line 8 def initialize(attributes = {}) raise ArgumentError, "attributes is not a Hash" unless attributes.is_a?(Hash) attributes = Leafy::Utils.symbolize_keys(attributes) self.name = attributes.fetch(:name) self.type = attributes.fetch(:type) self.id = attributes.fetch(:id) { [name.downcase.strip.tr(" ", "-"), SecureRandom.uuid].join("-") } self. = attributes.fetch(:metadata, {}) end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
6 7 8 |
# File 'lib/leafy/field.rb', line 6 def id @id end |
#metadata ⇒ Object
Returns the value of attribute metadata.
6 7 8 |
# File 'lib/leafy/field.rb', line 6 def @metadata end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/leafy/field.rb', line 6 def name @name end |
#type ⇒ Object
Returns the value of attribute type.
6 7 8 |
# File 'lib/leafy/field.rb', line 6 def type @type end |
Instance Method Details
#serializable_hash ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/leafy/field.rb', line 18 def serializable_hash { name: name, type: type, id: id, metadata: } end |