Class: Goaltender::ValueParser::HasMany
- Inherits:
-
Goaltender::ValueParser
- Object
- Goaltender::ValueParser
- Goaltender::ValueParser::HasMany
- Defined in:
- lib/goaltender/value_parser/has_many.rb
Instance Attribute Summary collapse
-
#form_class ⇒ Object
readonly
Returns the value of attribute form_class.
-
#variable_name ⇒ Object
readonly
Returns the value of attribute variable_name.
Attributes inherited from Goaltender::ValueParser
Instance Method Summary collapse
- #after_init(args) ⇒ Object
-
#parse ⇒ Object
should return a pattern like…
Methods inherited from Goaltender::ValueParser
Constructor Details
This class inherits a constructor from Goaltender::ValueParser
Instance Attribute Details
#form_class ⇒ Object (readonly)
Returns the value of attribute form_class.
5 6 7 |
# File 'lib/goaltender/value_parser/has_many.rb', line 5 def form_class @form_class end |
#variable_name ⇒ Object (readonly)
Returns the value of attribute variable_name.
5 6 7 |
# File 'lib/goaltender/value_parser/has_many.rb', line 5 def variable_name @variable_name end |
Instance Method Details
#after_init(args) ⇒ Object
7 8 9 10 |
# File 'lib/goaltender/value_parser/has_many.rb', line 7 def after_init(args) @form_class = args[:form_class] @variable_name = args[:variable_name] end |
#parse ⇒ Object
should return a pattern like… {
loads_attributes: {
"0" => {
pays_fuel_surcharge: true,
pickup_datetime: #datetime_object
}
}
}
21 22 23 24 25 26 27 28 29 |
# File 'lib/goaltender/value_parser/has_many.rb', line 21 def parse return input_value unless input_value.present? hash = {} input_value.each do |index, obj_hash| object_hash = form_class.constantize.new(obj_hash).to_h hash[index] = object_hash end hash end |