Class: Holoserve::Tool::Merger

Inherits:
Object
  • Object
show all
Defined in:
lib/holoserve/tool/merger.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash_or_array_one, hash_or_array_two, mode = :union) ⇒ Merger

Returns a new instance of Merger.



6
7
8
# File 'lib/holoserve/tool/merger.rb', line 6

def initialize(hash_or_array_one, hash_or_array_two, mode = :union)
  @hash_or_array_one, @hash_or_array_two, @mode = hash_or_array_one, hash_or_array_two, mode
end

Instance Attribute Details

#modeObject

Returns the value of attribute mode.



4
5
6
# File 'lib/holoserve/tool/merger.rb', line 4

def mode
  @mode
end

Instance Method Details

#resultObject



10
11
12
13
14
15
16
17
18
# File 'lib/holoserve/tool/merger.rb', line 10

def result
  if @hash_or_array_one.is_a?(Hash) && @hash_or_array_two.is_a?(Hash)
    merged_hash
  elsif @hash_or_array_one.is_a?(Array) && @hash_or_array_two.is_a?(Array)
    merged_array
  else
    @hash_or_array_two
  end
end