Class: ReportHandler
- Inherits:
-
Object
- Object
- ReportHandler
- Defined in:
- lib/reporter.rb
Instance Method Summary collapse
- #build(report_headers, report_body, jsonify) ⇒ Object
-
#initialize(report_name = "report.rpt") ⇒ ReportHandler
constructor
A new instance of ReportHandler.
Constructor Details
#initialize(report_name = "report.rpt") ⇒ ReportHandler
Returns a new instance of ReportHandler.
2 3 4 |
# File 'lib/reporter.rb', line 2 def initialize(report_name = "report.rpt") @report_name = report_name end |
Instance Method Details
#build(report_headers, report_body, jsonify) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/reporter.rb', line 7 def build(report_headers, report_body, jsonify) return puts "Invalid use of \"jsonify\"." if !jsonify.is_a? (Hash) current_time = Time.now if jsonify[:jsonify] == false report_file = File.open(@report_name, "w") do |file_line| report_headers.each do |header_hash| header_hash.each do |k, v| file_line.puts "#{k}: #{v}\r\n" end end file_line.puts "Date/Time: #{current_time}" file_line.puts "\r\n\r\nReport Body:\r\n#{report_body}" end elsif jsonify[:jsonify] == true report_file = File.open(@report_name, "w") do |file_line| file_line.puts '[{' report_headers.each do |header_hash| header_hash.each do |k, v| file_line.puts "{\"#{k}\":\"#{v}\"},\r\n" end end file_line.puts "{\"Date_Time\":\"#{current_time}\"}," file_line.puts "{\"Report_Body\":\"#{report_body}\"}\r\n}]" end end end |