Class: SimpleParams::NestedClassList

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_params/nested_class_list.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent) ⇒ NestedClassList

Returns a new instance of NestedClassList.



5
6
7
# File 'lib/simple_params/nested_class_list.rb', line 5

def initialize(parent)
  @parent = parent
end

Instance Attribute Details

#parentObject (readonly)

Returns the value of attribute parent.



3
4
5
# File 'lib/simple_params/nested_class_list.rb', line 3

def parent
  @parent
end

Instance Method Details

#class_instancesObject



23
24
25
26
27
28
# File 'lib/simple_params/nested_class_list.rb', line 23

def class_instances
  nested_class_hash.each_pair.inject([]) do |array, (_key, value)|
    array << value
    array.flatten.compact
  end
end

#get_class_key(klass) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/simple_params/nested_class_list.rb', line 13

def get_class_key(klass)
  nested_class_hash.each do |key, value|
    if value.is_a?(Array)
      return key if value.include?(klass)
    else
      return key if value == klass
    end
  end
end

#to_hashObject



9
10
11
# File 'lib/simple_params/nested_class_list.rb', line 9

def to_hash
  nested_class_hash
end