Class: Goaltender::ValueParser::HasMany

Inherits:
Goaltender::ValueParser show all
Defined in:
lib/goaltender/value_parser/has_many.rb

Instance Attribute Summary collapse

Attributes inherited from Goaltender::ValueParser

#input_value

Instance Method Summary collapse

Methods inherited from Goaltender::ValueParser

#initialize

Constructor Details

This class inherits a constructor from Goaltender::ValueParser

Instance Attribute Details

#form_classObject (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_nameObject (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

#parseObject

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