Class: Gerd::Formatters::FileFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/gerd/formatters.rb

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ FileFormatter

Returns a new instance of FileFormatter.



21
22
23
# File 'lib/gerd/formatters.rb', line 21

def initialize(file)
  @file = file
end

Instance Method Details



25
26
27
28
29
30
31
32
33
34
# File 'lib/gerd/formatters.rb', line 25

def print(hash, options = {})
  
  if(File.exists?(@file))
    puts "The file #{@file} already exists. Use -o or --overwrite" unless options[:overwrite]
    return unless options[:overwrite]
  end
  output_file = File.new(@file, "w")
  content = JSON.pretty_generate(hash)
  output_file.write(content)
end