Class: Calendario::Renderers::MonthRenderer Private

Inherits:
Object
  • Object
show all
Defined in:
lib/calendario/renderers/month_renderer.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Renders a month line by line

Constant Summary collapse

EMPTY_DAY_SPACES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

The space of an empty day

Returns:

  • (String)
'  '.freeze
WEEKDAY_INITIALS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Initials of each week day

Returns:

  • (String)
'Su Mo Tu We Th Fr Sa'.freeze
MONTH_WIDTH =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Width of a rendered month

Returns:

  • (Integer)
20

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMonthRenderer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initializes a month renderer



34
35
36
# File 'lib/calendario/renderers/month_renderer.rb', line 34

def initialize
  @filter = proc { |date| date.day.to_s.rjust(2) }
end

Instance Attribute Details

#filterProc

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

A proc to be executed on each date to define what is displayed on each day

Returns:

  • (Proc)


28
29
30
# File 'lib/calendario/renderers/month_renderer.rb', line 28

def filter
  @filter
end

Instance Method Details

#render(month) ⇒ RenderedMonth

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Renders a month

Parameters:

  • month (Month)

    The month to be rendered

Returns:



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/calendario/renderers/month_renderer.rb', line 44

def render(month)
  weeks = build_weeks(month).map { |week| week.join(' ') }

  lines = [
    center_name(month),
    WEEKDAY_INITIALS,
    *weeks
  ]

  RenderedMonth.new(lines)
end