Class: Gerd::Formatters::FileFormatter
- Inherits:
-
Object
- Object
- Gerd::Formatters::FileFormatter
- Defined in:
- lib/gerd/formatters.rb
Instance Method Summary collapse
-
#initialize(file) ⇒ FileFormatter
constructor
A new instance of FileFormatter.
- #print(hash, options = {}) ⇒ Object
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
#print(hash, options = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/gerd/formatters.rb', line 25 def print(hash, = {}) if(File.exists?(@file)) puts "The file #{@file} already exists. Use -o or --overwrite" unless [:overwrite] return unless [:overwrite] end output_file = File.new(@file, "w") content = JSON.pretty_generate(hash) output_file.write(content) end |