Class: TerminalCalendar::Selection::MonthPage

Inherits:
Object
  • Object
show all
Defined in:
lib/terminal_calendar/selection/month_page.rb

Constant Summary collapse

WEEK_ROW =
%w(Su Mo Tu We Th Fr Sa).freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(month, pastel = Pastel.new) ⇒ MonthPage

Returns a new instance of MonthPage.



13
14
15
16
17
# File 'lib/terminal_calendar/selection/month_page.rb', line 13

def initialize(month, pastel=Pastel.new)
  @selection_grid = Grid.build_from_objects(month.as_rows)
  @month = month
  @pastel = pastel
end

Instance Attribute Details

#monthObject (readonly)

Returns the value of attribute month.



7
8
9
# File 'lib/terminal_calendar/selection/month_page.rb', line 7

def month
  @month
end

#selection_gridObject (readonly)

Returns the value of attribute selection_grid.



7
8
9
# File 'lib/terminal_calendar/selection/month_page.rb', line 7

def selection_grid
  @selection_grid
end

Class Method Details

.build(month) ⇒ Object



9
10
11
# File 'lib/terminal_calendar/selection/month_page.rb', line 9

def self.build(month)
  new(month)
end

Instance Method Details

#line_countObject



33
34
35
# File 'lib/terminal_calendar/selection/month_page.rb', line 33

def line_count
  @line_count ||= render_rows.count
end

#redraw_linesObject



25
26
27
28
29
30
31
# File 'lib/terminal_calendar/selection/month_page.rb', line 25

def redraw_lines
  if selection_grid.redraw_at.nil? || selection_grid.redraw_at.negative?
    calendar_header(selected: selection_grid&.redraw_at == -1).concat(selection_grid.redraw_lines)
  else
    selection_grid.redraw_lines
  end
end

#renderString

Renders the calendar as a string.

Returns:

  • (String)

    the rendered calendar as a string.



21
22
23
# File 'lib/terminal_calendar/selection/month_page.rb', line 21

def render
  render_rows.join("\n")
end

#selection_grid_linesObject



37
38
39
# File 'lib/terminal_calendar/selection/month_page.rb', line 37

def selection_grid_lines
  selection_grid.render_lines
end