Class: Rokaki::FilterModel::DeepAssignStruct
- Inherits:
-
Object
- Object
- Rokaki::FilterModel::DeepAssignStruct
- Defined in:
- lib/rokaki/filter_model/deep_assign_struct.rb
Instance Attribute Summary collapse
-
#keys ⇒ Object
readonly
Returns the value of attribute keys.
-
#struct ⇒ Object
Returns the value of attribute struct.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(keys:, value:, struct: nil) ⇒ DeepAssignStruct
constructor
A new instance of DeepAssignStruct.
Constructor Details
#initialize(keys:, value:, struct: nil) ⇒ DeepAssignStruct
Returns a new instance of DeepAssignStruct.
6 7 8 9 10 |
# File 'lib/rokaki/filter_model/deep_assign_struct.rb', line 6 def initialize(keys:, value:, struct: nil) @keys = keys @value = value @struct = struct end |
Instance Attribute Details
#keys ⇒ Object (readonly)
Returns the value of attribute keys.
11 12 13 |
# File 'lib/rokaki/filter_model/deep_assign_struct.rb', line 11 def keys @keys end |
#struct ⇒ Object
Returns the value of attribute struct.
12 13 14 |
# File 'lib/rokaki/filter_model/deep_assign_struct.rb', line 12 def struct @struct end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
11 12 13 |
# File 'lib/rokaki/filter_model/deep_assign_struct.rb', line 11 def value @value end |
Instance Method Details
#call ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rokaki/filter_model/deep_assign_struct.rb', line 14 def call base_keys = keys i = base_keys.length - 1 base_keys.reverse_each.reduce (value) do |struc,key| i -= 1 cur_keys = base_keys[0..i] if struct val = struct.dig(*cur_keys) val[key] = struc p val return val else if key.is_a?(Integer) struct = [struc] else { key=>struc } end end end end |