Class: StimulusReflex::Dataset
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- StimulusReflex::Dataset
- Includes:
- AttributeBuilder
- Defined in:
- lib/stimulus_reflex/dataset.rb
Instance Attribute Summary collapse
-
#attrs ⇒ Object
Returns the value of attribute attrs.
-
#data_attrs ⇒ Object
Returns the value of attribute data_attrs.
Instance Method Summary collapse
- #boolean ⇒ Object
-
#initialize(data = {}) ⇒ Dataset
constructor
A new instance of Dataset.
- #numeric ⇒ Object
- #signed ⇒ Object
- #unsigned ⇒ Object
Methods included from AttributeBuilder
#build_data_attrs, #build_underscored
Constructor Details
#initialize(data = {}) ⇒ Dataset
Returns a new instance of Dataset.
10 11 12 13 14 15 16 17 |
# File 'lib/stimulus_reflex/dataset.rb', line 10 def initialize(data = {}) datasets = data["dataset"] || {} regular_dataset = datasets["dataset"] || {} @attrs = build_data_attrs(regular_dataset, datasets["datasetAll"] || {}) @data_attrs = @attrs.transform_keys { |key| key.delete_prefix "data-" } super build_underscored(@data_attrs) end |
Instance Attribute Details
#attrs ⇒ Object
Returns the value of attribute attrs.
8 9 10 |
# File 'lib/stimulus_reflex/dataset.rb', line 8 def attrs @attrs end |
#data_attrs ⇒ Object
Returns the value of attribute data_attrs.
8 9 10 |
# File 'lib/stimulus_reflex/dataset.rb', line 8 def data_attrs @data_attrs end |
Instance Method Details
#boolean ⇒ Object
27 28 29 |
# File 'lib/stimulus_reflex/dataset.rb', line 27 def boolean @boolean ||= ->(accessor) { cast_boolean(self[accessor]) || self[accessor].blank? } end |
#numeric ⇒ Object
31 32 33 |
# File 'lib/stimulus_reflex/dataset.rb', line 31 def numeric @numeric ||= ->(accessor) { Float(self[accessor]) } end |
#signed ⇒ Object
19 20 21 |
# File 'lib/stimulus_reflex/dataset.rb', line 19 def signed @signed ||= ->(accessor) { GlobalID::Locator.locate_signed(self[accessor]) } end |
#unsigned ⇒ Object
23 24 25 |
# File 'lib/stimulus_reflex/dataset.rb', line 23 def unsigned @unsigned ||= ->(accessor) { GlobalID::Locator.locate(self[accessor]) } end |