Class: Koyomi::Calendar
- Includes:
- Helper::Week
- Defined in:
- lib/koyomi/calendar.rb
Constant Summary
Constants included from Helper::Week
Helper::Week::DEFAULT_WEEK_START, Helper::Week::WEEK_DAYS, Helper::Week::WEEK_START_RANGE, Helper::Week::WEEK_WDAYS
Instance Attribute Summary collapse
-
#koyomi_month ⇒ Object
readonly
——————–# instance methods.
-
#month ⇒ Object
readonly
——————–# instance methods.
-
#week_start ⇒ Object
Returns the value of attribute week_start.
-
#year ⇒ Object
readonly
——————–# instance methods.
Class Method Summary collapse
-
.of(date, week_start = nil) ⇒ Koyomi::Calendar
create Koyomi::Calendar instance from date.
Instance Method Summary collapse
-
#cycles(weeks, wdays) ⇒ Array<Date>
cycle dates.
-
#first ⇒ Date
first date of the calendar (NOT first date of the MONTH).
-
#initialize(year = nil, month = nil, week_start = nil) ⇒ Calendar
constructor
initialize instance.
-
#last ⇒ Date
last date of the calendar (NOT last date of the MONTH).
-
#nth_wday(nth, wday_name) ⇒ Date
week day of nth week.
-
#range ⇒ Range
range of the calendar.
-
#the_month ⇒ Koyomi::Month
Koyomi::Month of the calendar’s month.
-
#wdays(wday_name) ⇒ Array<Date>
week days.
-
#weeks ⇒ Array<Week>
weeks of the calendar.
Methods included from Helper::Week
Constructor Details
#initialize(year = nil, month = nil, week_start = nil) ⇒ Calendar
initialize instance
29 30 31 32 33 34 35 36 |
# File 'lib/koyomi/calendar.rb', line 29 def initialize(year = nil, month = nil, week_start = nil) super() self.year = year||self.created_at.year self.month = month||self.created_at.month self.week_start = week_start||DEFAULT_WEEK_START self.koyomi_month = Koyomi::Month.new(self.month, self.year) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Koyomi::Period
Instance Attribute Details
#koyomi_month ⇒ Object
——————–# instance methods
21 22 23 |
# File 'lib/koyomi/calendar.rb', line 21 def koyomi_month @koyomi_month end |
#month ⇒ Object
——————–# instance methods
21 22 23 |
# File 'lib/koyomi/calendar.rb', line 21 def month @month end |
#week_start ⇒ Object
Returns the value of attribute week_start.
22 23 24 |
# File 'lib/koyomi/calendar.rb', line 22 def week_start @week_start end |
#year ⇒ Object
——————–# instance methods
21 22 23 |
# File 'lib/koyomi/calendar.rb', line 21 def year @year end |
Class Method Details
.of(date, week_start = nil) ⇒ Koyomi::Calendar
create Koyomi::Calendar instance from date.
15 16 17 |
# File 'lib/koyomi/calendar.rb', line 15 def self.of(date, week_start = nil) self.new(date.year, date.month, week_start) end |
Instance Method Details
#cycles(weeks, wdays) ⇒ Array<Date>
cycle dates
116 117 118 |
# File 'lib/koyomi/calendar.rb', line 116 def cycles(weeks, wdays) self.koyomi_month.cycles(weeks, wdays) end |
#first ⇒ Date
first date of the calendar (NOT first date of the MONTH)
48 49 50 |
# File 'lib/koyomi/calendar.rb', line 48 def first Koyomi::Week.new(self.koyomi_month.first, self.week_start).first end |
#last ⇒ Date
last date of the calendar (NOT last date of the MONTH)
55 56 57 |
# File 'lib/koyomi/calendar.rb', line 55 def last Koyomi::Week.new(self.koyomi_month.last, self.week_start).last end |
#nth_wday(nth, wday_name) ⇒ Date
week day of nth week.
93 94 95 |
# File 'lib/koyomi/calendar.rb', line 93 def nth_wday(nth, wday_name) self.koyomi_month.nth_wday(nth, wday_name) end |
#range ⇒ Range
range of the calendar.
62 63 64 |
# File 'lib/koyomi/calendar.rb', line 62 def range Range.new(self.first, self.last) end |
#the_month ⇒ Koyomi::Month
Koyomi::Month of the calendar’s month.
69 70 71 |
# File 'lib/koyomi/calendar.rb', line 69 def the_month self.koyomi_month end |