Class: Runt::EveryTE

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

Overview

Using the precision from the supplied start argument and the its date value, matches every n number of time units thereafter.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TExpr

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

Constructor Details

#initialize(start, n, precision = nil) ⇒ EveryTE

Returns a new instance of EveryTE.



767
768
769
770
771
772
# File 'lib/runt/temporalexpression.rb', line 767

def initialize(start,n,precision=nil)
  @start=start
  @interval=n
  # Use the precision of the start date by default
  @precision=precision || @start.date_precision
end

Instance Attribute Details

#intervalObject (readonly)

Returns the value of attribute interval.



765
766
767
# File 'lib/runt/temporalexpression.rb', line 765

def interval
  @interval
end

#precisionObject (readonly)

Returns the value of attribute precision.



765
766
767
# File 'lib/runt/temporalexpression.rb', line 765

def precision
  @precision
end

#startObject (readonly)

Returns the value of attribute start.



765
766
767
# File 'lib/runt/temporalexpression.rb', line 765

def start
  @start
end

Instance Method Details

#==(o) ⇒ Object



774
775
776
# File 'lib/runt/temporalexpression.rb', line 774

def ==(o)
  o.is_a?(EveryTE) ? start == o.start && precision == o.precision && interval == o.interval  : super(o)
end

#include?(date) ⇒ Boolean

Returns:

  • (Boolean)


778
779
780
781
782
783
784
785
786
# File 'lib/runt/temporalexpression.rb', line 778

def include?(date)
  i=DPrecision.to_p(@start,@precision)
  d=DPrecision.to_p(date,@precision)
  while i<=d
    return true if i.eql?(d)
    i=i+@interval      
  end
  false
end

#to_sObject



788
789
790
# File 'lib/runt/temporalexpression.rb', line 788

def to_s
  "every #{@interval} #{@precision.label.downcase}s starting #{Runt.format_date(@start)}"
end