Class: Txtout
- Inherits:
-
Object
- Object
- Txtout
- Defined in:
- lib/newsman/txt_output.rb
Overview
This class knows how to print a report to a separate file.
Instance Method Summary collapse
- #filename(reporter) ⇒ Object
-
#initialize(root = '.') ⇒ Txtout
constructor
A new instance of Txtout.
- #print(report, reporter) ⇒ Object
Constructor Details
Instance Method Details
#filename(reporter) ⇒ Object
38 39 40 41 |
# File 'lib/newsman/txt_output.rb', line 38 def filename(reporter) date = Time.new.strftime('%d.%m.%Y') "#{date}.#{reporter}.txt" end |
#print(report, reporter) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/newsman/txt_output.rb', line 29 def print(report, reporter) puts "Create a file in a directory #{@root}" file = File.new(File.join(@root, filename(reporter)), 'w') puts "File #{file.path} was successfully created" file.puts report puts "Report was successfully printed to a #{file.path}" file.close end |