Class: Timet::TimeBlockChart
- Inherits:
-
Object
- Object
- Timet::TimeBlockChart
- Defined in:
- lib/timet/time_block_chart.rb
Overview
The TimeBlockChart class is responsible for generating and printing a visual representation of time blocks for a given set of data. It uses character mapping to represent different time ranges and provides methods to print the chart with headers, footers, and colored blocks.
Example usage:
time_block = {
"2023-10-01" => { "08" => [3600, "work"], "09" => [1800, "break"] },
"2023-10-02" => { "10" => [4500, "work"] }
}
colors = { "work" => 31, "break" => 32 }
chart = TimeBlockChart.new(table)
chart.print_time_block_chart(table, colors)
Constant Summary collapse
- SEPARATOR_CHAR =
Separator character for the chart
'░'
- DATE_WEEK_CONTENT_WIDTH =
Width of the date/week string content (e.g., “02 2023-10-01 Fri”)
17
- DATE_WEEK_BORDER_WIDTH =
Width of the ‘┆- ’ part after the date/week string
3
- TOTAL_HOURS_COLUMN_WIDTH =
Width of the total hours column including the border
4
Instance Attribute Summary collapse
-
#end_hour ⇒ Integer
readonly
The ending hour of the time block.
-
#start_hour ⇒ Integer
readonly
The starting hour of the time block.
Instance Method Summary collapse
-
#initialize(table) ⇒ void
constructor
Initializes a new TimeBlockChart instance.
-
#print_time_block_chart(colors) ⇒ void
Prints the time block chart.
Constructor Details
#initialize(table) ⇒ void
-
The ‘@time_block` instance variable is populated by processing the time entries from the table.
-
The ‘@start_hour` and `@end_hour` instance variables are calculated based on the earliest and latest hours present in the time block data.
Initializes a new TimeBlockChart instance.
This method sets up the time block chart by processing the time entries from the provided table and determining the start and end hours for the chart based on the time block data.
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/timet/time_block_chart.rb', line 50 def initialize(table) @time_block = table.process_time_entries(display: false) hours = @time_block.values.map(&:keys).flatten.uniq if hours.empty? @start_hour = @end_hour = 0 return end @start_hour = hours.min.to_i @end_hour = hours.max.to_i end |
Instance Attribute Details
#end_hour ⇒ Integer (readonly)
The ending hour of the time block
23 24 25 |
# File 'lib/timet/time_block_chart.rb', line 23 def end_hour @end_hour end |
#start_hour ⇒ Integer (readonly)
The starting hour of the time block
23 24 25 |
# File 'lib/timet/time_block_chart.rb', line 23 def start_hour @start_hour end |
Instance Method Details
#print_time_block_chart(colors) ⇒ void
-
The method first prints the header of the chart, which includes the time range.
-
It then prints the time blocks, using the provided color mapping to visually distinguish between different tags.
This method returns an undefined value.
Prints the time block chart.
This method formats and prints the time block chart, including the header and the time blocks for each entry. The chart is color-coded based on the provided color mapping for different tags.
82 83 84 85 86 87 |
# File 'lib/timet/time_block_chart.rb', line 82 def print_time_block_chart(colors) return puts 'No time-block data to display.' if @no_data print_header print_blocks(colors) end |