Class: Cal::MonthlyCalendar
- Inherits:
-
Object
- Object
- Cal::MonthlyCalendar
- Defined in:
- lib/cal/monthly_calendar.rb
Constant Summary collapse
- DAY_NAMES =
{ :sunday => 0, :monday => 1, :tuesday => 2, :wednesday => 3, :thursday => 4, :friday => 5, :saturday => 6 }
Instance Attribute Summary collapse
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#month ⇒ Object
readonly
Returns the value of attribute month.
-
#year ⇒ Object
readonly
Returns the value of attribute year.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #day_names ⇒ Object
- #days ⇒ Object
- #first_day ⇒ Object
-
#initialize(dateable, options = {}) ⇒ MonthlyCalendar
constructor
A new instance of MonthlyCalendar.
- #last_day ⇒ Object
- #next ⇒ Object
- #previous ⇒ Object
- #weeks ⇒ Object
Constructor Details
#initialize(dateable, options = {}) ⇒ MonthlyCalendar
Returns a new instance of MonthlyCalendar.
17 18 19 20 21 22 |
# File 'lib/cal/monthly_calendar.rb', line 17 def initialize(dateable, = {}) @date = dateable.to_date @start_week_on = [:start_week_on] || :sunday @month = Month.new self @year = Year.new self end |
Instance Attribute Details
#date ⇒ Object (readonly)
Returns the value of attribute date.
24 25 26 |
# File 'lib/cal/monthly_calendar.rb', line 24 def date @date end |
#month ⇒ Object (readonly)
Returns the value of attribute month.
24 25 26 |
# File 'lib/cal/monthly_calendar.rb', line 24 def month @month end |
#year ⇒ Object (readonly)
Returns the value of attribute year.
24 25 26 |
# File 'lib/cal/monthly_calendar.rb', line 24 def year @year end |
Instance Method Details
#==(other) ⇒ Object
26 27 28 29 30 |
# File 'lib/cal/monthly_calendar.rb', line 26 def ==(other) other.is_a?(MonthlyCalendar) && other.date.year == date.year && other.date.month == date.month end |
#day_names ⇒ Object
56 57 58 |
# File 'lib/cal/monthly_calendar.rb', line 56 def day_names %w[Sunday Monday Tuesday Wednesday Thursday Friday Saturday].rotate DAY_NAMES[@start_week_on] end |
#days ⇒ Object
40 41 42 |
# File 'lib/cal/monthly_calendar.rb', line 40 def days @days ||= first_day..last_day end |
#first_day ⇒ Object
32 33 34 |
# File 'lib/cal/monthly_calendar.rb', line 32 def first_day @first_day ||= Day.new date.beginning_of_month.beginning_of_week(@start_week_on), self end |
#last_day ⇒ Object
36 37 38 |
# File 'lib/cal/monthly_calendar.rb', line 36 def last_day @last_day ||= Day.new date.end_of_month.end_of_week(@start_week_on), self end |
#next ⇒ Object
52 53 54 |
# File 'lib/cal/monthly_calendar.rb', line 52 def next self.class.new date.next_month end |
#previous ⇒ Object
48 49 50 |
# File 'lib/cal/monthly_calendar.rb', line 48 def previous self.class.new date.prev_month end |
#weeks ⇒ Object
44 45 46 |
# File 'lib/cal/monthly_calendar.rb', line 44 def weeks @weeks ||= days.to_a.in_groups_of 7 end |