forked from Moutix/idmef_parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
yaml_to_json.rb
33 lines (29 loc) · 851 Bytes
/
yaml_to_json.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
require 'json'
require 'yaml'
class YamlToJson
def initialize json="json", yaml="yaml"
@json = json
@yaml = yaml
end
def convert_to_json
Dir.glob("#{@yaml}/*.yml").each do |yaml|
File.open(yaml) do |f|
File.open("#{@json}/#{File.basename(f.path, ".*")}.json", "w") do |fw|
fw.write(JSON.pretty_generate(YAML.load(f.read)))
end
end
end
end
def convert_to_yaml
Dir.glob("#{@json}/*.json").each do |json|
File.open(json) do |f|
File.open("#{@yaml}/#{File.basename(f.path, ".*")}.yml", "w") do |fw|
fw.write(YAML.dump(JSON.load(f.read)))
end
end
end
end
end
YamlToJson.new("idmef/json", "idmef/yaml").convert_to_json
YamlToJson.new("iodef/json", "iodef/yaml").convert_to_json
YamlToJson.new("idmefv2/json", "idmefv2/yaml").convert_to_json