Class: Worklog::Printer
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Worklog::Printer
- Defined in:
- lib/worklog/printer.rb
Instance Method Summary collapse
-
#initialize(sheet) ⇒ Printer
constructor
A new instance of Printer.
- #prev_month ⇒ Object
- #prev_week ⇒ Object
- #print(report, subtitle = "") ⇒ Object
- #this_month ⇒ Object
- #this_week ⇒ Object
- #tracks(filter = ->(x,_){true}) ⇒ Object
Constructor Details
#initialize(sheet) ⇒ Printer
Returns a new instance of Printer.
8 9 10 11 |
# File 'lib/worklog/printer.rb', line 8 def initialize(sheet) @sheet = sheet super end |
Instance Method Details
#prev_month ⇒ Object
47 48 49 50 |
# File 'lib/worklog/printer.rb', line 47 def prev_month subtitle = "for #{(Date.today << 1).strftime("%B %Y")}" print(super(), subtitle) end |
#prev_week ⇒ Object
57 58 59 60 |
# File 'lib/worklog/printer.rb', line 57 def prev_week subtitle = prev_week_title print(super(), subtitle) end |
#print(report, subtitle = "") ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/worklog/printer.rb', line 13 def print(report, subtitle = "") # TODO: provide spec for "no traks found" if report[:items].empty? puts "No tracks found" return end puts "-= #{report[:title]} #{subtitle} =-" puts %w(Date Year Month Week Spent Reward Task).join(?\t) report[:items].each do |track| row = [].tap do |r| r << track.date.to_s r << track.date.year r << track.date.strftime('%B') r << track.date.cweek r << format_spent(track.spent) r << track.reward.to_s(?F) r << track.task end.join(?\t) puts row end puts puts "Total time\t#{format_spent(report[:spent])}" puts "Total\t%.2f" % report[:total] end |
#this_month ⇒ Object
42 43 44 45 |
# File 'lib/worklog/printer.rb', line 42 def this_month subtitle = "for #{Date.today.strftime("%B %Y")}" print(super(), subtitle); end |
#this_week ⇒ Object
52 53 54 55 |
# File 'lib/worklog/printer.rb', line 52 def this_week subtitle = this_week_title print(super(), subtitle) end |
#tracks(filter = ->(x,_){true}) ⇒ Object
38 39 40 |
# File 'lib/worklog/printer.rb', line 38 def tracks(filter = ->(x,_){true}) print(super(&filter)) end |