Class: Printer
- Inherits:
-
Object
- Object
- Printer
- Defined in:
- lib/printer.rb
Overview
Printer for work log entries
Instance Attribute Summary collapse
-
#people ⇒ Object
readonly
Returns the value of attribute people.
Instance Method Summary collapse
-
#initialize(configuration, people = nil) ⇒ Printer
constructor
Initializes the printer with a list of people.
-
#no_entries(start_date, end_date) ⇒ void
Print a message when no entries are found.
-
#print_day(daily_log, date_inline = false, epics_only = false, filter = {}) ⇒ void
Prints a whole day of work log entries.
-
#print_entry(daily_log, entry, date_inline = false) ⇒ Object
Prints a single entry, formats the date and time.
-
#terminal_width ⇒ Integer
Returns the width of the terminal.
Constructor Details
#initialize(configuration, people = nil) ⇒ Printer
Initializes the printer with a list of people.
12 13 14 15 |
# File 'lib/printer.rb', line 12 def initialize(configuration, people = nil) @configuration = configuration @people = people || {} end |
Instance Attribute Details
#people ⇒ Object (readonly)
Returns the value of attribute people.
7 8 9 |
# File 'lib/printer.rb', line 7 def people @people end |
Instance Method Details
#no_entries(start_date, end_date) ⇒ void
This method returns an undefined value.
Print a message when no entries are found.
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/printer.rb', line 55 def no_entries(start_date, end_date) if start_date == end_date date_string = start_date.strftime('%a, %B %-d, %Y') puts "No entries found for #{Rainbow(date_string).gold}." else start_date_string = start_date.strftime('%a, %B %-d, %Y') end_date_string = end_date.strftime('%a, %B %-d, %Y') puts "No entries found between #{Rainbow(start_date_string).gold} and #{Rainbow(end_date_string).gold}." end end |
#print_day(daily_log, date_inline = false, epics_only = false, filter = {}) ⇒ void
This method returns an undefined value.
Prints a whole day of work log entries. If date_inline is true, the date is printed inline with the time. If epics_only is true, only epic entries are printed.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/printer.rb', line 28 def print_day(daily_log, date_inline = false, epics_only = false, filter = {}) daily_log.date = Date.strptime(daily_log.date, '%Y-%m-%d') unless daily_log.date.respond_to?(:strftime) date_string = daily_log.date.strftime('%a, %B %-d, %Y') preamble = "Work log for #{Rainbow(date_string).gold}" puts preamble unless date_inline # Print only if there are entries to show, especially when epics_only is true entries_count = daily_log.entries.count do |entry| (!epics_only || entry.epic?) && filter.compact.all? { |k, v| entry.send(k) == v } end puts Rainbow('-' * preamble.gsub(/\e\[[0-9;]*m/, '').length).gold if entries_count.positive? daily_log.entries.each do |entry| next if epics_only && !entry.epic? next unless filter.compact.all? { |k, v| entry.send(k) == v } print_entry(daily_log, entry, date_inline) end end |
#print_entry(daily_log, entry, date_inline = false) ⇒ Object
Prints a single entry, formats the date and time.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/printer.rb', line 70 def print_entry(daily_log, entry, date_inline = false) # Backwards compatibility: convert strings to Date/Time objects if necessary entry.time = Time.strptime(entry.time, '%H:%M:%S') unless entry.time.respond_to?(:strftime) # Convert to local time zone entry.time = entry.time.getlocal(@configuration.timezone) if @configuration.timezone time_string = if date_inline "#{daily_log.date.strftime('%a, %Y-%m-%d')} #{entry.time.strftime('%H:%M')}" else entry.time.strftime('%H:%M') end print ' ' unless date_inline puts "#{Rainbow(time_string).gold} #{entry.(@people)}" end |
#terminal_width ⇒ Integer
Returns the width of the terminal.
88 89 90 |
# File 'lib/printer.rb', line 88 def terminal_width IO.console.winsize[1] end |