Class: Timet::WeekInfo
- Inherits:
-
Object
- Object
- Timet::WeekInfo
- Defined in:
- lib/timet/week_info.rb
Overview
The WeekInfo class encapsulates the date string and weeks array and provides methods for formatting and determining week information.
It is instantiated for each date entry in the TimeBlockChart and helps decide how the week number is displayed and whether a separator line is needed before the entry.
Constant Summary collapse
- WEEKEND_DAYS =
Initializes a new WeekInfo instance.
%w[Sat Sun].freeze
Instance Method Summary collapse
-
#format_and_print_date_info(day) ⇒ void
Formats and prints the date information.
-
#initialize(date_object, date_string_for_display, weeks_array_ref) ⇒ WeekInfo
constructor
A new instance of WeekInfo.
-
#needs_inter_week_separator? ⇒ Boolean
Indicates whether an inter-week separator line should be printed before this date’s entry.
Constructor Details
#initialize(date_object, date_string_for_display, weeks_array_ref) ⇒ WeekInfo
Returns a new instance of WeekInfo.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/timet/week_info.rb', line 21 def initialize(date_object, date_string_for_display, weeks_array_ref) @date_string = date_string_for_display # Use the passed string for display @current_cweek = date_object.cweek # Determine if a separator line should be printed *before* this entry. # A separator is needed if this entry starts a new week group, # and it's not the very first week group in the chart. @print_separator_before_this = !weeks_array_ref.empty? && @current_cweek != weeks_array_ref.last # Determine how the week number string should be displayed for this entry. # It's underlined if it's the first time this cweek appears, otherwise blank. is_first_display_of_this_cweek = weeks_array_ref.empty? || @current_cweek != weeks_array_ref.last @week_display_string = if is_first_display_of_this_cweek format('%02d', @current_cweek).underline else ' ' end weeks_array_ref << @current_cweek # Record this week as processed end |
Instance Method Details
#format_and_print_date_info(day) ⇒ void
This method returns an undefined value.
Formats and prints the date information
53 54 55 56 57 58 59 60 |
# File 'lib/timet/week_info.rb', line 53 def format_and_print_date_info(day) weekend_str = @date_string # Use the original date string for display is_weekend_day = WEEKEND_DAYS.include?(day) day_str = is_weekend_day ? day.red : day weekend_str = weekend_str.red if is_weekend_day print '┆'.gray + "#{@week_display_string} #{weekend_str} #{day_str}" + '┆- '.gray end |
#needs_inter_week_separator? ⇒ Boolean
Indicates whether an inter-week separator line should be printed before this date’s entry.
45 46 47 |
# File 'lib/timet/week_info.rb', line 45 def needs_inter_week_separator? @print_separator_before_this end |