Class: Calendario::Calendar

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

Overview

A time period to be rendered

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(year_renderer = Renderers::YearRenderer.new) ⇒ Calendar

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.

Initialize a calendar

table of 3 columns by 4 rows

Parameters:



20
21
22
# File 'lib/calendario/calendar.rb', line 20

def initialize(year_renderer = Renderers::YearRenderer.new)
  @year_renderer = year_renderer
end

Instance Attribute Details

#year_rendererCalendario::Renderers::YearRenderer (readonly)

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 year, line by line, in a table of 3 columns by 4 rows



12
13
14
# File 'lib/calendario/calendar.rb', line 12

def year_renderer
  @year_renderer
end

Instance Method Details

#render_current_year(&block) ⇒ RenderedYear

Renders the current year as a string

Examples:

Rendering the current year

calendar = Calendario::Calendar.new
calendar.render_current_year

Rendering a customized version of the current year

calendar = Calendario::Calendar.new
calendar.render_current_year do |date|
  if date.wday == 5 ||  if date.wday == 6
    'WE'
  else
    date.day.to_s.rjust(2)
  end
end

Returns:



44
45
46
47
# File 'lib/calendario/calendar.rb', line 44

def render_current_year(&block)
  year = Year.new(Date.today.year)
  year_renderer.render(year, &block)
end