Class: Runt::DIWeek

Inherits:
Object
  • Object
show all
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 Method Summary collapse

Methods included from TExpr

#&, #-, #and, #dates, #minus, #or, #|

Constructor Details

#initialize(ordinal_weekday) ⇒ DIWeek

Returns a new instance of DIWeek.



352
353
354
355
356
357
# File 'lib/runt/temporalexpression.rb', line 352

def initialize(ordinal_weekday)
  unless VALID_RANGE.include?(ordinal_weekday)
    raise ArgumentError, 'invalid ordinal day of week'
  end
  @ordinal_weekday = ordinal_weekday
end

Instance Method Details

#include?(date) ⇒ Boolean

Returns:

  • (Boolean)


359
360
361
# File 'lib/runt/temporalexpression.rb', line 359

def include?(date)
  @ordinal_weekday == date.wday
end

#to_sObject



363
364
365
# File 'lib/runt/temporalexpression.rb', line 363

def to_s
  "#{Runt.day_name(@ordinal_weekday)}"
end