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 Attribute Summary collapse
-
#day_index ⇒ Object
readonly
Returns the value of attribute day_index.
-
#week_of_month_index ⇒ Object
readonly
Returns the value of attribute week_of_month_index.
Instance Method Summary collapse
- #==(o) ⇒ Object
- #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
346 347 348 349 |
# 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 |
Instance Attribute Details
#day_index ⇒ Object (readonly)
Returns the value of attribute day_index.
344 345 346 |
# File 'lib/runt/temporalexpression.rb', line 344 def day_index @day_index end |
#week_of_month_index ⇒ Object (readonly)
Returns the value of attribute week_of_month_index.
344 345 346 |
# File 'lib/runt/temporalexpression.rb', line 344 def week_of_month_index @week_of_month_index end |
Instance Method Details
#==(o) ⇒ Object
351 352 353 |
# 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) ⇒ Boolean
355 356 357 |
# File 'lib/runt/temporalexpression.rb', line 355 def include?(date) ( day_matches?(date) ) && ( week_matches?(@week_of_month_index,date) ) end |
#to_s ⇒ Object
359 360 361 |
# 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 |