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
|
# File 'lib/genericode/cli/converter.rb', line 6
def self.convert(input_path, output_path)
input_format = File.extname(input_path)
output_format = File.extname(output_path)
raise Error, 'Invalid input format' unless ['.gc',
'.gcj'].include?(input_format)
raise Error, 'Invalid output format' unless ['.gc',
'.gcj'].include?(output_format)
if input_format == output_format
raise Error,
'Input and output formats are the same'
end
code_list = CodeList.from_file(input_path)
result = if output_format == '.gcj'
code_list.to_json
else
code_list.to_xml
end
File.write(output_path, result)
true
end
|