Class: Runt::WIMonth

Inherits:
Object
  • Object
show all
Includes:
TExpr, TExprUtils
Defined in:
lib/runt/temporalexpression.rb

Overview

TExpr that matches the week in a month. For example:

   WIMonth.new(1)

See also: Date
FIXME .dates mixin seems functionally broken

Constant Summary collapse

VALID_RANGE =
-2..5

Instance Method Summary collapse

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(ordinal) ⇒ WIMonth

Returns a new instance of WIMonth.



636
637
638
639
640
641
# File 'lib/runt/temporalexpression.rb', line 636

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

Instance Method Details

#include?(date) ⇒ Boolean

Returns:

  • (Boolean)


643
644
645
# File 'lib/runt/temporalexpression.rb', line 643

def include?(date)
  week_matches?(@ordinal,date)
end

#to_sObject



647
648
649
# File 'lib/runt/temporalexpression.rb', line 647

def to_s
  "#{Runt.ordinalize(@ordinal)} week of any month"
end