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, #last_day_of_window, register_parse_callback, #to_s, #window

Constructor Details

#initialize(*terms) ⇒ MultiTermBase

Create an multi-term temporal expression.



244
245
246
# File 'lib/texp/base.rb', line 244

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.



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

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:



260
261
262
263
# File 'lib/texp/base.rb', line 260

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.



249
250
251
252
253
254
255
256
# File 'lib/texp/base.rb', line 249

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