Class: TExp::MultiTermBase

Inherits:
Base
  • Object
show all
Defined in:
lib/texp/base.rb

Overview

Base class for temporal expressions with multiple sub-expressions (i.e. terms).

Direct Known Subclasses

And, Or

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#*, #+, #-, #-@, #first_day_of_window, #include?, #last_day_of_window, register_parse_callback, #to_s, #window

Constructor Details

#initialize(*terms) ⇒ MultiTermBase

Create an multi-term temporal expression.



254
255
256
# File 'lib/texp/base.rb', line 254

def initialize(*terms)
  @terms = terms
end

Class Method Details

.parse_callback(stack) ⇒ Object

Parsing callback for terms based temporal expressions. The top of the stack is assumed to be a list that is *-expanded to the temporal expression’s constructor.



279
280
281
# File 'lib/texp/base.rb', line 279

def parse_callback(stack)
  stack.push self.new(*stack.pop)
end

Instance Method Details

#each {|_self| ... } ⇒ Object

Iterate over all temporal expressions and subexpressions (in post order).

Yields:

  • (_self)

Yield Parameters:



270
271
272
273
# File 'lib/texp/base.rb', line 270

def each()                  # :yield: temporal_expression
  @terms.each do |term| yield term end
  yield self
end

#reanchor(date) ⇒ Object

Create a new temporal expression with a new anchor date.



259
260
261
262
263
264
265
266
# File 'lib/texp/base.rb', line 259

def reanchor(date)
  new_terms = @terms.collect { |term| term.reanchor(date) }
  if new_terms == @terms
    self
  else
    self.class.new(*new_terms)
  end
end