Class: Suprdate::Month
Constant Summary collapse
- STRFTIME_STR =
'%Y-%m'
Instance Attribute Summary collapse
-
#day_factory ⇒ Object
Returns the value of attribute day_factory.
-
#year ⇒ Object
readonly
Returns the value of attribute year.
Attributes inherited from Unit
Instance Method Summary collapse
-
#+(increase) ⇒ Object
Return a new month incremented by an integer.
-
#-(decrease) ⇒ Object
Return a new month decremented by an integer.
- #<=>(operand) ⇒ Object
-
#day(*indices) ⇒ Object
(also: #[])
A choice of some specific days from this month.
-
#days ⇒ Object
All the days in this month.
- #inspect ⇒ Object
-
#leap? ⇒ Boolean
Whether this month contains a leap day.
- #month ⇒ Object
-
#num_days ⇒ Object
Number of day in this month.
- #of_year_as_s ⇒ Object
- #of_year_as_sym ⇒ Object
-
#since(operand) ⇒ Object
Number of months since parameter#month.
-
#succ ⇒ Object
Next successive month.
-
#to_sym ⇒ Object
Name of month as symbol.
-
#until(operand) ⇒ Object
Number of months until parameter#month.
Methods inherited from Unit
<=>, #==, #hash, #new, significance, #to_s
Methods included from Utility::CleanConstantName
Instance Attribute Details
#day_factory ⇒ Object
Returns the value of attribute day_factory.
5 6 7 |
# File 'lib/suprdate/month.rb', line 5 def day_factory @day_factory end |
#year ⇒ Object (readonly)
Returns the value of attribute year.
6 7 8 |
# File 'lib/suprdate/month.rb', line 6 def year @year end |
Instance Method Details
#+(increase) ⇒ Object
Return a new month incremented by an integer.
67 |
# File 'lib/suprdate/month.rb', line 67 def +(increase) new_from_sum(sum + increase) end |
#-(decrease) ⇒ Object
Return a new month decremented by an integer.
70 |
# File 'lib/suprdate/month.rb', line 70 def -(decrease) new_from_sum(sum - decrease) end |
#<=>(operand) ⇒ Object
54 55 56 57 58 |
# File 'lib/suprdate/month.rb', line 54 def <=>(operand) return -1 if operand == Infinity operand = operand.month (@year.value * NUM_MONTHS_IN_YEAR + @value) - (operand.year.value * NUM_MONTHS_IN_YEAR + operand.value) end |
#day(*indices) ⇒ Object Also known as: []
A choice of some specific days from this month.
40 41 42 43 44 45 46 47 |
# File 'lib/suprdate/month.rb', line 40 def day(*indices) indices = [1] if indices.empty? rval = indices.map do |i| i = num_days + 1 - i.abs if i < 0 day_factory.new(self, i) end Utility::disarray(rval) end |
#days ⇒ Object
All the days in this month
35 36 37 |
# File 'lib/suprdate/month.rb', line 35 def days (1..num_days).to_a.map { |i| day_factory.new(self, i) } end |
#inspect ⇒ Object
52 |
# File 'lib/suprdate/month.rb', line 52 def inspect() "#@year-#{@value.to_s.rjust(2, '0')}" end |
#leap? ⇒ Boolean
Whether this month contains a leap day.
50 |
# File 'lib/suprdate/month.rb', line 50 def leap?() @value == 2 && @year.leap? end |
#month ⇒ Object
77 |
# File 'lib/suprdate/month.rb', line 77 def month() self end |
#num_days ⇒ Object
Number of day in this month.
29 30 31 32 |
# File 'lib/suprdate/month.rb', line 29 def num_days return 29 if leap? NUM_DAYS_IN_MONTHS[@value] end |
#of_year_as_s ⇒ Object
76 |
# File 'lib/suprdate/month.rb', line 76 def of_year_as_s() MONTHS_AS_STR[@value] end |
#of_year_as_sym ⇒ Object
75 |
# File 'lib/suprdate/month.rb', line 75 def of_year_as_sym() MONTHS_AS_SYM[@value] end |
#since(operand) ⇒ Object
Number of months since parameter#month.
61 |
# File 'lib/suprdate/month.rb', line 61 def since(operand) sum - operand.month.sum end |
#succ ⇒ Object
Next successive month.
73 |
# File 'lib/suprdate/month.rb', line 73 def succ() self + 1 end |
#to_sym ⇒ Object
Name of month as symbol.
26 |
# File 'lib/suprdate/month.rb', line 26 def to_sym() MONTHS_AS_SYM[@value] end |
#until(operand) ⇒ Object
Number of months until parameter#month.
64 |
# File 'lib/suprdate/month.rb', line 64 def until(operand) operand.month.sum - sum end |