Class: Timet::TimeReport
- Inherits:
-
Object
- Object
- Timet::TimeReport
- Includes:
- TagDistribution, TimeReportHelper
- Defined in:
- lib/timet/time_report.rb
Overview
The TimeReport class is responsible for displaying a report of tracked time entries. It allows filtering the report by time periods and displays a formatted table with the relevant information.
Constant Summary
Constants included from TagDistribution
Timet::TagDistribution::BLOCK_CHAR, Timet::TagDistribution::MAX_BAR_LENGTH, Timet::TagDistribution::TAG_SIZE
Instance Attribute Summary collapse
-
#csv_filename ⇒ Object
readonly
Provides access to the CSV filename.
-
#db ⇒ Object
readonly
Provides access to the database instance.
-
#ics_filename ⇒ Object
readonly
Provides access to the ICS filename.
-
#items ⇒ Object
readonly
Provides access to the filtered items.
Instance Method Summary collapse
-
#display ⇒ void
Displays the report of tracked time entries.
-
#initialize(db, options = {}) ⇒ void
constructor
Initializes a new instance of the TimeReport class.
-
#print_tag_explanation_report ⇒ void
Prints the tag distribution explanation.
-
#show_row(item) ⇒ void
Displays a single row of the report.
Methods included from TagDistribution
#calculate_value_and_bar_length, #generate_horizontal_bar, #generate_stats, #print_explanation, #print_footer, #print_summary, #print_tags_info, #process_and_print_tags, #tag_distribution
Methods included from TimeReportHelper
#export_csv, #export_icalendar
Constructor Details
#initialize(db, options = {}) ⇒ void
-
If no filter is provided, all items from the database will be fetched.
-
The ‘@table` instance variable is initialized with the filtered items and filter configuration.
Initializes a new instance of the TimeReport class.
58 59 60 61 62 63 64 65 66 |
# File 'lib/timet/time_report.rb', line 58 def initialize(db, = {}) @db = db @csv_filename = [:csv] @ics_filename = [:ics] @filter = formatted_filter([:filter]) @search_query = [:search] @items = [:filter] ? filter_items(@filter, [:tag], @search_query) : @db.all_items @table = Table.new(@filter, @items, @db) end |
Instance Attribute Details
#csv_filename ⇒ Object (readonly)
Provides access to the CSV filename.
26 27 28 |
# File 'lib/timet/time_report.rb', line 26 def csv_filename @csv_filename end |
#db ⇒ Object (readonly)
Provides access to the database instance.
20 21 22 |
# File 'lib/timet/time_report.rb', line 20 def db @db end |
#ics_filename ⇒ Object (readonly)
Provides access to the ICS filename.
29 30 31 |
# File 'lib/timet/time_report.rb', line 29 def ics_filename @ics_filename end |
#items ⇒ Object (readonly)
Provides access to the filtered items.
23 24 25 |
# File 'lib/timet/time_report.rb', line 23 def items @items end |
Instance Method Details
#display ⇒ void
-
The method checks if there are any tracked time entries. If not, it prints a message and exits.
-
It uses the ‘@table` instance to format and display the table.
-
A time block chart is generated and printed using the ‘TimeBlockChart` class.
-
The tag distribution is calculated and displayed based on the unique colors assigned to tags.
This method returns an undefined value.
Displays the report of tracked time entries.
This method formats and prints the report, including the table header, rows, total duration, a time block chart, and tag distribution. If no tracked time entries are found for the specified filter, it displays a message indicating no data is available.
88 89 90 91 92 93 94 95 96 |
# File 'lib/timet/time_report.rb', line 88 def display return puts 'No tracked time found for the specified filter.' if @items.empty? @table.table colors = @items.map { |x| x[3] }.uniq.each_with_index.to_h chart = TimeBlockChart.new(@table) chart.print_time_block_chart(colors) tag_distribution(colors) end |
#print_tag_explanation_report ⇒ void
This method returns an undefined value.
Prints the tag distribution explanation. This method is a public wrapper for the private ‘print_explanation` method from the `TagDistribution` module.
103 104 105 106 107 |
# File 'lib/timet/time_report.rb', line 103 def print_tag_explanation_report time_stats = TimeStatistics.new(@items) total = time_stats.total_duration print_explanation(time_stats, total) if total.positive? end |
#show_row(item) ⇒ void
-
The method uses the ‘@table` instance to format and display the table header and row.
-
A separator is printed after the row to visually distinguish it from other rows.
-
The total duration is displayed at the end of the row.
This method returns an undefined value.
Displays a single row of the report.
This method formats and prints a single row of the report, including the table header, the specified row, a separator, and the total duration. It is used to display individual time entries in a structured format.
129 130 131 132 133 134 |
# File 'lib/timet/time_report.rb', line 129 def show_row(item) @table.header @table.display_time_entry(item) puts @table.separator @table.total end |