Sha256: a130125fad282a1e6860bc769f301cf138c18c7cd477f218cb82dc6ca013bbde
Contents?: true
Size: 1.16 KB
Versions: 6
Compression:
Stored size: 1.16 KB
Contents
module Aigu class Mergeer def initialize(opts = {}) @output_file = opts[:'output-file'] @input_directory = opts[:'input-directory'] end def process! puts "Generating flat Accent JSON file `#{@output_file}` merging json files in `#{@input_directory}` directory" puts '---' build_output write_json_file puts '---' puts 'Done' end protected def build_output @output = {} pattern = File.join(@input_directory, '*.json') Dir[pattern].each do |filepath| puts "Processing #{filepath}" file_name = filepath.rpartition(File::SEPARATOR).last.split('.', 2).first prefix = file_name == 'default' ? '' : "@#{file_name.upcase}@__" json = JSON.parse(File.read(filepath)) json.each_pair do |key, value| @output[prefix + key] = value end end @output end def write_json_file file_path = @output_file puts "Generating #{file_path}" FileUtils.mkdir_p(File.dirname(file_path)) File.open(file_path, 'w+') do |file| file << JSON.pretty_generate(JSON.parse(@output.to_json)) end end end end
Version data entries
6 entries across 6 versions & 1 rubygems
Version | Path |
---|---|
aigu-0.4.5 | lib/aigu/mergeer.rb |
aigu-0.4.4 | lib/aigu/mergeer.rb |
aigu-0.4.3 | lib/aigu/mergeer.rb |
aigu-0.4.2 | lib/aigu/mergeer.rb |
aigu-0.4.1 | lib/aigu/mergeer.rb |
aigu-0.4 | lib/aigu/mergeer.rb |