Sha256: c5a5a76a7a48a217b8f9565950a065deac9c6f79c769a4965018e5a47b4d3a85
Contents?: true
Size: 784 Bytes
Versions: 1
Compression:
Stored size: 784 Bytes
Contents
require 'json' module Gerd module Formatters def self.find_formatter(file) return Gerd::Formatters::Stdout.new unless file return Gerd::Formatters::FileFormatter.new(file) end class Stdout def print(hash, options = {}) puts JSON.pretty_generate(hash) end end class FileFormatter def initialize(file) @file = file end 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 end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
gerd-0.0.1 | lib/gerd/formatters.rb |