Abstract Base class for all Texp Temporal Expressions.

Methods
Included Modules
Attributes
[R] encoding_token The token to be used for encoding this temporal expression.
Public Instance methods
*(texp)

Combine two temporal expressions so that the result will match the intersection of the dates matched by the individual temporal expressions.

Examples:

   month("Feb") * day(14) # Match the 14th of February (in any year)
    # File lib/texp/operators.rb, line 24
24:     def *(texp)
25:       TExp::And.new(self, texp)
26:     end
+(texp)

Combine two temporal expressions so that the result will match the union of the dates matched by the individual temporal expressions.

Examples:

   dow(:monday) + dow(:tuesday) # Match any date falling on Monday or Tuesday
    # File lib/texp/operators.rb, line 12
12:     def +(texp)
13:       TExp::Or.new(self, texp)
14:     end
-(texp)

Combine two temporal expressions so that the result will match the any date matched by left expression except for dates matched by the right expression.

Examples:

   month("Feb") - dow(:mon)    # Match any day in February except Mondays
    # File lib/texp/operators.rb, line 36
36:     def -(texp)
37:       TExp::And.new(self, TExp::Not.new(texp))
38:     end
-@()

Return a new temporal expression that negates the sense of the current expression. In other words, match everything the current expressions does not match and don‘t match anything that it does.

Examples:

   -dow(:mon)    # Match everything but Mondays
    # File lib/texp/operators.rb, line 49
49:     def -@()
50:       TExp::Not.new(self)
51:     end
each() {|temporal_expression| ...}

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

    # File lib/texp/base.rb, line 37
37:     def each()                  # :yield: temporal_expression
38:       yield self
39:     end
first_day_of_window(date)

Return the first day of the window for the temporal expression. If the temporal expression is not a windowed expression, then the first day of the window is the given date.

    # File lib/texp/base.rb, line 24
24:     def first_day_of_window(date)
25:       includes?(date) ? date : nil
26:     end
last_day_of_window(date)

Return the last day of the window for the temporal expression. If the temporal expression is not a windowed expression, then the last day of the window is the given date.

    # File lib/texp/base.rb, line 31
31:     def last_day_of_window(date)
32:       includes?(date) ? date : nil
33:     end
reanchor(date)

Create a new temporal expression with a new anchor date.

    # File lib/texp/base.rb, line 17
17:     def reanchor(date)
18:       self
19:     end
to_s()

Convert the temporal expression into an encoded string (that can be parsed by TExp.parse).

    # File lib/texp/base.rb, line 10
10:     def to_s
11:       codes = []
12:       encode(codes)
13:       codes.join("")
14:     end
window(days)
window(predays, postdays)
window(n, units)
window(pre, pre_units, post, post_units)

Create a new temporal expression that matches a window around any date matched by the current expression.

If a single numeric value is given, then a symetrical window of the given number of days is created around each date matched by the current expression. If a symbol representing units is given in addition to the numeric, then the appropriate scale factor is applied to the numeric value.

If two numberic values are given (with or without unit symbols), then the window will be asymmetric. The firsts numeric value will be the pre-window, and the second numeric value will be the post window.

The following unit symbols are recognized:

  • :day, :days (scale by 1)
  • :week, :weeks (scale by 7)
  • :month, :months (scale by 30)
  • :year, :years (scale by 365)

Examples:

  texp.window(3)         # window of 3 days on either side
  texp.window(3, :days)  # window of 3 days on either side
  texp.window(1, :week)  # window of 1 week on either side
  texp.window(3, :days, 2, :weeks)
                         # window of 3 days before any match,
                         # and 2 weeks after any match.
    # File lib/texp/base.rb, line 77
77:     def window(*args)
78:       prewindow, postwindow = TExp.normalize_units(args)
79:       postwindow ||= prewindow
80:       TExp::Window.new(self, prewindow, postwindow)
81:     end