Class: RspecApiDocs::Resource::Example::DeepHashSet

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec_api_docs/formatter/resource/example/deep_hash_set.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash, keys, value) ⇒ DeepHashSet

Returns a new instance of DeepHashSet.



11
12
13
14
15
16
# File 'lib/rspec_api_docs/formatter/resource/example/deep_hash_set.rb', line 11

def initialize(hash, keys, value)
  @hash = hash
  @keys = keys
  @value = value
  @node = []
end

Instance Attribute Details

#hashObject (readonly)

Returns the value of attribute hash.



5
6
7
# File 'lib/rspec_api_docs/formatter/resource/example/deep_hash_set.rb', line 5

def hash
  @hash
end

#keysObject (readonly)

Returns the value of attribute keys.



5
6
7
# File 'lib/rspec_api_docs/formatter/resource/example/deep_hash_set.rb', line 5

def keys
  @keys
end

#valueObject (readonly)

Returns the value of attribute value.



5
6
7
# File 'lib/rspec_api_docs/formatter/resource/example/deep_hash_set.rb', line 5

def value
  @value
end

Class Method Details

.call(*args) ⇒ Object



7
8
9
# File 'lib/rspec_api_docs/formatter/resource/example/deep_hash_set.rb', line 7

def self.call(*args)
  new(*args).call
end

Instance Method Details

#callObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rspec_api_docs/formatter/resource/example/deep_hash_set.rb', line 18

def call
  keys.each_with_index do |key, index|
    case
    when key.nil?
      deep_set_value_at_array(index)
      break
    when index == keys.size - 1
      set_value_at(key)
    else
      node << key
    end
  end

  hash
end