Class: Separatum::Exporters::JsonFile

Inherits:
Object
  • Object
show all
Defined in:
lib/separatum/exporters/json_file.rb

Instance Method Summary collapse

Constructor Details

#initialize(file_name:, pretty_print: false) ⇒ JsonFile

Returns a new instance of JsonFile.



4
5
6
7
# File 'lib/separatum/exporters/json_file.rb', line 4

def initialize(file_name:, pretty_print: false)
  @file_name = file_name
  @pretty_print = pretty_print
end

Instance Method Details

#call(*hashes) ⇒ Object



9
10
11
12
13
14
# File 'lib/separatum/exporters/json_file.rb', line 9

def call(*hashes)
  hashes.flatten!
  str = @pretty_print ? JSON.pretty_generate(hashes) : JSON.dump(hashes)
  File.write(@file_name, str)
  hashes
end