Class: Runt::DayIntervalTE

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

Overview

Using day precision dates, matches every n number of days after a given base date. All date arguments are converted to DPrecision::DAY precision.

Contributed by Ira Burton

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TExpr

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

Constructor Details

#initialize(base_date, n) ⇒ DayIntervalTE

Returns a new instance of DayIntervalTE.



804
805
806
807
# File 'lib/runt/temporalexpression.rb', line 804

def initialize(base_date,n)
  @base_date = DPrecision.to_p(base_date,DPrecision::DAY)
  @interval = n
end

Instance Attribute Details

#base_dateObject (readonly)

Returns the value of attribute base_date.



802
803
804
# File 'lib/runt/temporalexpression.rb', line 802

def base_date
  @base_date
end

#intervalObject (readonly)

Returns the value of attribute interval.



802
803
804
# File 'lib/runt/temporalexpression.rb', line 802

def interval
  @interval
end

Instance Method Details

#==(o) ⇒ Object



809
810
811
# File 'lib/runt/temporalexpression.rb', line 809

def ==(o)
  o.is_a?(DayIntervalTE) ? base_date == o.base_date && interval == o.interval  : super(o)
end

#include?(date) ⇒ Boolean

Returns:

  • (Boolean)


813
814
815
# File 'lib/runt/temporalexpression.rb', line 813

def include?(date)
  return ((DPrecision.to_p(date,DPrecision::DAY) - @base_date).to_i % @interval == 0)   
end

#to_sObject



817
818
819
# File 'lib/runt/temporalexpression.rb', line 817

def to_s
  "every #{Runt.ordinalize(@interval)} day after #{Runt.format_date(@base_date)}"
end