Class: Danica::VariablesHolder::Store

Inherits:
Object
  • Object
show all
Defined in:
lib/danica/variables_holder/store.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(default_variables_hash) ⇒ Store

Returns a new instance of Store.



7
8
9
10
# File 'lib/danica/variables_holder/store.rb', line 7

def initialize(default_variables_hash)
  @default_variables_hash = default_variables_hash
  @variables_names = default_variables_hash.keys
end

Instance Attribute Details

#default_variables_hashObject (readonly)

Returns the value of attribute default_variables_hash.



5
6
7
# File 'lib/danica/variables_holder/store.rb', line 5

def default_variables_hash
  @default_variables_hash
end

#variables_namesObject (readonly)

Returns the value of attribute variables_names.



5
6
7
# File 'lib/danica/variables_holder/store.rb', line 5

def variables_names
  @variables_names
end

Instance Method Details

#containersObject



16
17
18
# File 'lib/danica/variables_holder/store.rb', line 16

def containers
  containers_hash.values
end

#containers_hashObject



12
13
14
# File 'lib/danica/variables_holder/store.rb', line 12

def containers_hash
  @containers_hash ||= {}.merge(default_containers_hash)
end

#extract_variablesObject



34
35
36
# File 'lib/danica/variables_holder/store.rb', line 34

def extract_variables
  inner_containers_hash.merge(named_variables_hash)
end

#variablesObject



20
21
22
# File 'lib/danica/variables_holder/store.rb', line 20

def variables
  containers.map(&:content)
end

#variables_hashObject



24
25
26
# File 'lib/danica/variables_holder/store.rb', line 24

def variables_hash
  containers_hash.change_values(&:content)
end

#variables_value_hashObject



28
29
30
31
32
# File 'lib/danica/variables_holder/store.rb', line 28

def variables_value_hash
  variables.map do |var|
    var.try(:value)
  end.as_hash(variables_names)
end