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 Attribute Summary collapse

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.



703
704
705
706
707
708
# File 'lib/runt/temporalexpression.rb', line 703

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

Instance Attribute Details

#ordinalObject (readonly)

Returns the value of attribute ordinal.



701
702
703
# File 'lib/runt/temporalexpression.rb', line 701

def ordinal
  @ordinal
end

Instance Method Details

#==(o) ⇒ Object



710
711
712
# File 'lib/runt/temporalexpression.rb', line 710

def ==(o)
  o.is_a?(WIMonth) ? ordinal == o.ordinal : super(o)
end

#include?(date) ⇒ Boolean

Returns:

  • (Boolean)


714
715
716
# File 'lib/runt/temporalexpression.rb', line 714

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

#to_sObject



718
719
720
# File 'lib/runt/temporalexpression.rb', line 718

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