Sha256: fd998ccfce5affa88694aeef5e5e68025b3a5b004cf035c4df588795fe3472b6
Contents?: true
Size: 1.25 KB
Versions: 5
Compression:
Stored size: 1.25 KB
Contents
module Aigu class Unmerger UNMERGE_REGEX = /^@(?<file_name>\w+)@__(?<key>.+)$/ def initialize(opts = {}) @output_directory = opts[:'output-directory'] @input_file = opts[:'input-file'] end def process! puts "Unmerging Accent json file `#{@input_file}` to `#{@output_directory}` directory" puts '---' parse_json write_json_files puts '---' puts 'Done' end protected def parse_json @object = {} json = JSON.parse(File.read(@input_file)) json.each_pair do |key, value| match_data = key.match(UNMERGE_REGEX) if match_data @object[match_data[:file_name]] ||= {} @object[match_data[:file_name]][match_data[:key]] = value else @object['DEFAULT'] ||= {} @object['DEFAULT'][key] = value end end @object end def write_json_files @object.each_pair do |file_name, json| file_path = File.join(@output_directory, "#{file_name.downcase}.json") puts "Generating #{file_path}" FileUtils.mkdir_p(File.dirname(file_path)) File.open(file_path, 'w+') do |file| file << JSON.pretty_generate(JSON.parse(json.to_json)) end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems
Version | Path |
---|---|
aigu-0.7 | lib/aigu/unmerger.rb |
aigu-0.6.1 | lib/aigu/unmerger.rb |
aigu-0.6 | lib/aigu/unmerger.rb |
aigu-0.5.1 | lib/aigu/unmerger.rb |
aigu-0.5 | lib/aigu/unmerger.rb |