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.



619
620
621
622
623
624
# File 'lib/runt/temporalexpression.rb', line 619

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)


626
627
628
# File 'lib/runt/temporalexpression.rb', line 626

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

#to_sObject



630
631
632
# File 'lib/runt/temporalexpression.rb', line 630

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