class ToFile::To
Private Class Methods
error_msg(data_type, err)
click to toggle source
# File lib/to_file.rb, line 56 def error_msg(data_type, err) 'target_object can not be transformed to ' + data_type.to_s + ' format! The error msg is: ' + err.to_s end
overwrite_confirm?(export_path)
click to toggle source
# File lib/to_file.rb, line 63 def overwrite_confirm?(export_path) msg = "\033[31mWARNING '" + export_path + "' is already existing, do you" msg += " want to overwrite it ??? please press 'y' or 'n' to confirm!( " msg += "tip: overwrite feature can be turned off manually by parameter): \033[0m" puts msg prompt = STDIN.gets.chomp until %w(y n).include? prompt.downcase do puts "\033[31mInvalid input, please input 'y' or 'n'\033[0m" prompt = STDIN.gets.chomp end prompt.downcase == 'y' ? true : false end
to_json(target_object)
click to toggle source
# File lib/to_file.rb, line 40 def to_json(target_object) begin JSON.pretty_generate target_object rescue => e raise ArgumentError, error_msg("json", e.message) end end
to_xml(target_object)
click to toggle source
# File lib/to_file.rb, line 48 def to_xml(target_object) begin target_object.to_xml rescue => e raise ArgumentError, error_msg("xml", e.message) end end
to_yml(target_object)
click to toggle source
# File lib/to_file.rb, line 32 def to_yml(target_object) begin target_object.to_yaml rescue => e raise ArgumentError, error_msg("yaml", e.message) end end