Class: Txtout

Inherits:
Object
  • Object
show all
Defined in:
lib/newsman/txt_output.rb

Overview

This class knows how to print a report to a separate file.

Instance Method Summary collapse

Constructor Details

#initialize(root = '.') ⇒ Txtout

Returns a new instance of Txtout.



25
26
27
# File 'lib/newsman/txt_output.rb', line 25

def initialize(root = '.')
  @root = root
end

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


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