class Runt::DIMonth
TExpr
that provides support for building a temporal expression using the form:
DIMonth.new(1,0)
where the first argument is the week of the month and the second argument is the wday of the week as defined by the ‘wday’ method in the standard library class Date
.
A negative value for the week of the month argument will count backwards from the end of the month. So, to match the last Saturday of the month
DIMonth.new(-1,6)
Using constants defined in the base Runt
module, you can re-write the first example above as:
DIMonth.new(First,Sunday)
and the second as:
DIMonth.new(Last,Saturday) See also: Date, Runt
Attributes
day_index[R]
week_of_month_index[R]
Public Class Methods
new(week_of_month_index,day_index)
click to toggle source
# File lib/runt/temporalexpression.rb, line 346 def initialize(week_of_month_index,day_index) @day_index = day_index @week_of_month_index = week_of_month_index end
Public Instance Methods
==(o)
click to toggle source
Calls superclass method
# File lib/runt/temporalexpression.rb, line 351 def ==(o) o.is_a?(DIMonth) ? day_index == o.day_index && week_of_month_index == o.week_of_month_index : super(o) end
include?(date)
click to toggle source
# File lib/runt/temporalexpression.rb, line 355 def include?(date) ( day_matches?(date) ) && ( week_matches?(@week_of_month_index,date) ) end
to_s()
click to toggle source
# File lib/runt/temporalexpression.rb, line 359 def to_s "#{Runt.ordinalize(@week_of_month_index)} #{Runt.day_name(@day_index)} of the month" end
Private Instance Methods
day_matches?(date)
click to toggle source
# File lib/runt/temporalexpression.rb, line 364 def day_matches?(date) @day_index == date.wday end