module SupermarketSync::Util

> Utility Methods

Public Instance Methods

parse_json(file = nil, symbolize = true) click to toggle source

> Define JSON Parser

# File lib/supermarket_sync/util.rb, line 23
def parse_json(file = nil, symbolize = true)
  return unless file && ::File.exist?(file.to_s)
  begin
    ::JSON.parse(::File.read(file.to_s), symbolize_names: symbolize)
  rescue JSON::ParserError => e
    puts "#{e.class}:: #{file}"
    return
  end
end
write_json(file, object) click to toggle source

> Define JSON Writer

# File lib/supermarket_sync/util.rb, line 34
def write_json(file, object)
  return unless file && object
  begin
    File.open(file, 'w') { |f| f.write(JSON.pretty_generate(object)) }
  end
end