Class: Tcelfer::CLI::Report
- Inherits:
-
Object
- Object
- Tcelfer::CLI::Report
- Defined in:
- lib/tcelfer/cli/report.rb
Overview
Generate reports with day/week/month/year granularity.
Class Method Summary collapse
-
.legend ⇒ Terminal::Table
Formats Tcelfer::RATING_TO_COLOR_MAP into a pretty legend Terminal::Table.
Instance Method Summary collapse
-
#generate_month_report(month, year = Date.today.year) ⇒ Terminal::Table
Takes a month and year and returns a pretty formatted Terminal::Table with days colored according to Tcelfer::RATING_TO_COLOR_MAP.
-
#initialize ⇒ Report
constructor
A new instance of Report.
-
#month_with_legend(month, year) ⇒ Terminal::Table
Same as generate_month_report except it includes a color legend.
Constructor Details
Class Method Details
.legend ⇒ Terminal::Table
Formats Tcelfer::RATING_TO_COLOR_MAP into a pretty legend Terminal::Table
59 60 61 62 63 64 |
# File 'lib/tcelfer/cli/report.rb', line 59 def self.legend leg = Tcelfer::RATING_TO_COLOR_MAP.map do |, color| [Paint[' ', :inverse, color], ] end Terminal::Table.new(rows: leg, headings: %w[Color Rating].map { |head| Paint[head, :bold] }) end |
Instance Method Details
#generate_month_report(month, year = Date.today.year) ⇒ Terminal::Table
Takes a month and year and returns a pretty formatted Terminal::Table with days colored according to Tcelfer::RATING_TO_COLOR_MAP
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/tcelfer/cli/report.rb', line 34 def generate_month_report(month, year = Date.today.year) mon_by_wday = @store.by_month(month, year).group_by { |day| day.date.wday } if mon_by_wday.length < 7 raise ReportError, "Unable to process #{Date::MONTHNAMES[month]}, please have at least 7 days of data first" end pad_month_start!(mon_by_wday) weeks = color_month(mon_by_wday) Terminal::Table.new(rows: weeks, style: { all_separators: true }, headings: Date::ABBR_DAYNAMES) end |
#month_with_legend(month, year) ⇒ Terminal::Table
Same as generate_month_report except it includes a color legend
49 50 51 52 53 54 55 |
# File 'lib/tcelfer/cli/report.rb', line 49 def month_with_legend(month, year) tab = generate_month_report(month, year) Terminal::Table.new(rows: [[tab, Report.legend]]).tap do |combined| combined.style = { border_x: '', border_y: '', border_i: '', width: `tput cols`.to_i } combined.headings = ["== #{Date::MONTHNAMES[month]} - #{year} ==", '== Legend =='] end end |