Class: JSONCombiner

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

Instance Method Summary collapse

Constructor Details

#initialize(*inputjsons) ⇒ JSONCombiner

Returns a new instance of JSONCombiner.



4
5
6
# File 'lib/jsoncombiner.rb', line 4

def initialize(*inputjsons)
  @inputjsons = inputjsons
end

Instance Method Details

#concatenateObject

Concatenates JSONs together



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/jsoncombiner.rb', line 9

def concatenate
  savearray = Array.new
  @inputjsons.each do |j|
    nextfile = JSON.parse(j)
    
    nextfile.each do |h|
       if !(savearray.include? h)
         savearray.push(h)
       end
    end
  end
  
  return JSON.pretty_generate(savearray)
end