Class: Runt::DIWeek
- Inherits:
-
Object
- Object
- Runt::DIWeek
- Includes:
- TExpr
- Defined in:
- lib/runt/temporalexpression.rb
Overview
TExpr that matches days of the week where the first argument is an integer denoting the ordinal day of the week. Valid values are 0..6 where 0 == Sunday and 6==Saturday
For example:
DIWeek.new(0)
Using constants defined in the base Runt module, you can re-write the first example above as:
DIWeek.new(Sunday)
See also: Date, Runt
Constant Summary collapse
- VALID_RANGE =
0..6
Instance Attribute Summary collapse
-
#ordinal_weekday ⇒ Object
readonly
Returns the value of attribute ordinal_weekday.
Instance Method Summary collapse
- #==(o) ⇒ Object
- #include?(date) ⇒ Boolean
-
#initialize(ordinal_weekday) ⇒ DIWeek
constructor
A new instance of DIWeek.
- #to_s ⇒ Object
Methods included from TExpr
#&, #-, #and, #dates, #minus, #or, #|
Constructor Details
#initialize(ordinal_weekday) ⇒ DIWeek
Returns a new instance of DIWeek.
392 393 394 395 396 397 |
# File 'lib/runt/temporalexpression.rb', line 392 def initialize(ordinal_weekday) unless VALID_RANGE.include?(ordinal_weekday) raise ArgumentError, 'invalid ordinal day of week' end @ordinal_weekday = ordinal_weekday end |
Instance Attribute Details
#ordinal_weekday ⇒ Object (readonly)
Returns the value of attribute ordinal_weekday.
390 391 392 |
# File 'lib/runt/temporalexpression.rb', line 390 def ordinal_weekday @ordinal_weekday end |
Instance Method Details
#==(o) ⇒ Object
399 400 401 |
# File 'lib/runt/temporalexpression.rb', line 399 def ==(o) o.is_a?(DIWeek) ? ordinal_weekday == o.ordinal_weekday : super(o) end |
#include?(date) ⇒ Boolean
403 404 405 |
# File 'lib/runt/temporalexpression.rb', line 403 def include?(date) @ordinal_weekday == date.wday end |