Class: Runt::DIMonth
- Inherits:
-
Object
- Object
- Runt::DIMonth
- Includes:
- TExpr, TExprUtils
- Defined in:
- lib/runt/temporalexpression.rb
Overview
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
Instance Method Summary collapse
- #include?(date) ⇒ Boolean
-
#initialize(week_of_month_index, day_index) ⇒ DIMonth
constructor
A new instance of DIMonth.
- #to_s ⇒ Object
Methods included from TExprUtils
#days_left_in_month, #max_day_of_month, #week_from_end_matches?, #week_from_start_matches?, #week_in_month, #week_matches?
Methods included from TExpr
#&, #-, #and, #dates, #minus, #or, #|
Constructor Details
#initialize(week_of_month_index, day_index) ⇒ DIMonth
Returns a new instance of DIMonth.
318 319 320 321 |
# File 'lib/runt/temporalexpression.rb', line 318 def initialize(week_of_month_index,day_index) @day_index = day_index @week_of_month_index = week_of_month_index end |
Instance Method Details
#include?(date) ⇒ Boolean
323 324 325 |
# File 'lib/runt/temporalexpression.rb', line 323 def include?(date) ( day_matches?(date) ) && ( week_matches?(@week_of_month_index,date) ) end |
#to_s ⇒ Object
327 328 329 |
# File 'lib/runt/temporalexpression.rb', line 327 def to_s "#{Runt.ordinalize(@week_of_month_index)} #{Runt.day_name(@day_index)} of the month" end |