-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsumo-sources-parser.rb
42 lines (36 loc) · 1001 Bytes
/
sumo-sources-parser.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
require 'json'
class SumoSources
def initialize(args)
exit 1 unless check_args(args)
@input_file_location = args[0]
@output_file_location = args[1]
@items = {}
puts "- Initializing vars -"
end
def write_file
return if @items.empty?
puts "Writing to file: " + @output_file_location
File.open(@output_file_location,"w") do |f|
f.puts((JSON.pretty_generate @items))
end
end
def read_files
Dir.glob(@input_file_location) do |rb_file|
puts "Reading file: " + rb_file
file = JSON.parse(File.read(rb_file))
next if file.empty?
@items.empty? ? @items = file : @items["sources"] += file["sources"]
end
end
def check_args(args)
args.delete("")
return false if args.empty?
rtn = true
puts "input_file_location is blank" && rtn = false if args[0] == ""
puts "output_file_location is blank" && rtn = false if args[1] == ""
return rtn
end
end
d = SumoSources.new(ARGV)
d.read_files
d.write_file