Module: SupermarketSync::Util
- Defined in:
- lib/supermarket_sync/util.rb
Overview
> Utility Methods
Class Method Summary collapse
-
.parse_json(file = nil, symbolize = true) ⇒ Object
> Define JSON Parser.
-
.write_json(file, object) ⇒ Object
> Define JSON Writer.
Class Method Details
.parse_json(file = nil, symbolize = true) ⇒ Object
> Define JSON Parser
23 24 25 26 27 28 29 30 31 |
# 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) ⇒ Object
> Define JSON Writer
34 35 36 37 38 39 |
# 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 |