Class: TExp::Window
- Inherits:
-
SingleTermBase
- Object
- Base
- SingleTermBase
- TExp::Window
- Defined in:
- lib/texp/window.rb
Class Method Summary collapse
-
.parse_callback(stack) ⇒ Object
Parsing callback for window temporal expressions.
Instance Method Summary collapse
-
#encode(codes) ⇒ Object
Encode the temporal expression into
codes
. -
#find_pivot(date) ⇒ Object
Find the matching date for the window.
-
#first_day_of_window(date) ⇒ Object
Return the first day of the window for a given date.
-
#includes?(date) ⇒ Boolean
Is
date
included in the temporal expression. -
#initialize(texp, prewindow_days, postwindow_days) ⇒ Window
constructor
A new instance of Window.
-
#inspect ⇒ Object
Human readable version of the temporal expression.
-
#last_day_of_window(date) ⇒ Object
Return the first day of the window for a given date.
Methods inherited from SingleTermBase
Methods inherited from Base
#*, #+, #-, #-@, #each, #include?, #reanchor, register_parse_callback, #to_s, #window
Constructor Details
Class Method Details
Instance Method Details
#encode(codes) ⇒ Object
Encode the temporal expression into codes
.
48 49 50 51 |
# File 'lib/texp/window.rb', line 48 def encode(codes) @term.encode(codes) codes << @prewindow_days << "," << @postwindow_days << "s" end |
#find_pivot(date) ⇒ Object
Find the matching date for the window.
31 32 33 34 35 36 37 38 |
# File 'lib/texp/window.rb', line 31 def find_pivot(date) d = date - @postwindow_days while d <= date + @prewindow_days return d if @term.includes?(d) d += 1 end return nil end |
#first_day_of_window(date) ⇒ Object
Return the first day of the window for a given date. Return nil if the date is not in a window.
18 19 20 21 |
# File 'lib/texp/window.rb', line 18 def first_day_of_window(date) pivot = find_pivot(date) pivot ? pivot - @prewindow_days : nil end |
#includes?(date) ⇒ Boolean
Is date
included in the temporal expression.
12 13 14 |
# File 'lib/texp/window.rb', line 12 def includes?(date) find_pivot(date) != nil end |
#inspect ⇒ Object
Human readable version of the temporal expression.
41 42 43 44 45 |
# File 'lib/texp/window.rb', line 41 def inspect @term.inspect + ", " + "or up to #{days(@prewindow_days)} prior, " + "or up to #{days(@postwindow_days)} after" end |
#last_day_of_window(date) ⇒ Object
Return the first day of the window for a given date. Return nil if the date is not in a window.
25 26 27 28 |
# File 'lib/texp/window.rb', line 25 def last_day_of_window(date) pivot = find_pivot(date) pivot ? pivot + @postwindow_days : nil end |