Class: Calendario::Renderers::IntervalRenderer

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

Overview

Renders a time interval, line by line, in a table

Direct Known Subclasses

YearRenderer

Constant Summary collapse

EMPTY_DAY_SPACES =

The space of an empty day

Returns:

  • (String)
'  '.freeze

Instance Method Summary collapse

Constructor Details

#initialize(month_renderer = MonthRenderer.new) ⇒ IntervalRenderer

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 interval renderer

Parameters:

  • month_renderer (MonthRenderer) (defaults to: MonthRenderer.new)

    A service to render a month line by line



18
19
20
# File 'lib/calendario/renderers/interval_renderer.rb', line 18

def initialize(month_renderer = MonthRenderer.new)
  @month_renderer = month_renderer
end

Instance Method Details

#render(interval, columns:, &block) ⇒ RenderedInterval

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.

Formats a time interval, line by line, in a table

Parameters:

  • interval (Interval)

    The time interval to be rendered.

Returns:



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/calendario/renderers/interval_renderer.rb', line 28

def render(interval, columns:, &block)
  month_renderer.filter = block if block_given?

  lines = []
  rendered_months = render_months(interval.months)

  rendered_months.each_slice(columns) do |months|
    0.upto(7) { |month_line| lines << take_row(month_line, months) }
    lines.push('') # Separate rows of months
  end

  RenderedInterval.new(lines)
end