class StructureButcher::Parser
Public Instance Methods
load_base64(filename)
click to toggle source
# File lib/structurebutcher.rb, line 183 def load_base64(filename) content = File.read(filename) return Base64.encode64(content) end
load_hocon(filename)
click to toggle source
# File lib/structurebutcher.rb, line 172 def load_hocon(filename) result = nil begin result = recursive_stringify_keys(Hocon.load(filename)) rescue msg = "Error parsing '" + filename + "': " + $!.message raise AbortException.new(msg) end return result end
load_json(filename)
click to toggle source
# File lib/structurebutcher.rb, line 138 def load_json(filename) file = File.read(filename) result = nil begin result = recursive_stringify_keys(JSON.parse(file)) rescue msg = "Error parsing '" + filename + "': " + $!.message raise ArgumentError.new(msg) end return result end
load_properties(filename)
click to toggle source
# File lib/structurebutcher.rb, line 161 def load_properties(filename) result = nil begin result = recursive_stringify_keys(JavaProperties.load(filename)) rescue msg = "Error parsing '" + filename + "': " + $!.message raise AbortException.new(msg) end return result end
load_structure(filename, format)
click to toggle source
# File lib/structurebutcher.rb, line 98 def load_structure(filename, format) begin case format when "json" return load_json(filename) when "yaml" return load_yaml(filename) when "properties" return load_properties(filename) when "javaprops" return load_properties(filename) when "hocon" return load_hocon(filename) when "base64" return load_base64(filename) else raise "Not implemented" end rescue Exception => e abort(e.message) end end
load_yaml(filename)
click to toggle source
# File lib/structurebutcher.rb, line 150 def load_yaml(filename) result = nil begin result = recursive_stringify_keys(YAML.load_file(filename)) rescue msg = "Error parsing '" + filename + "': " + $!.message raise AbortException.new(msg) end return result end
recursive_stringify_keys(h)
click to toggle source
# File lib/structurebutcher.rb, line 121 def recursive_stringify_keys(h) case h when Hash Hash[ h.map do |k, v| [ k.respond_to?(:to_s) ? k.to_s : k, recursive_stringify_keys(v) ] end ] when Enumerable h.map { |v| recursive_stringify_keys(v) } else h end end