Class: TimeSeries
- Inherits:
-
Object
- Object
- TimeSeries
- Defined in:
- lib/asdrubal/time_series.rb
Instance Attribute Summary collapse
-
#smooth_window ⇒ Object
Returns the value of attribute smooth_window.
Class Method Summary collapse
Instance Method Summary collapse
- #[](date) ⇒ Object
- #[]=(date, value) ⇒ Object
- #at(date) ⇒ Object
- #each ⇒ Object
- #include?(date) ⇒ Boolean
-
#initialize(from_date, to_date = from_date, step_days = 1) ⇒ TimeSeries
constructor
A new instance of TimeSeries.
- #step(days) ⇒ Object
- #to(year, month, day) ⇒ Object
Constructor Details
#initialize(from_date, to_date = from_date, step_days = 1) ⇒ TimeSeries
Returns a new instance of TimeSeries.
4 5 6 7 8 9 |
# File 'lib/asdrubal/time_series.rb', line 4 def initialize(from_date, to_date = from_date, step_days = 1) @span = (from_date..to_date) @step = step_days @dates = Hash.new(0) self.smooth_window = 2 end |
Instance Attribute Details
#smooth_window ⇒ Object
Returns the value of attribute smooth_window.
2 3 4 |
# File 'lib/asdrubal/time_series.rb', line 2 def smooth_window @smooth_window end |
Class Method Details
.from(year, month, day) ⇒ Object
11 12 13 |
# File 'lib/asdrubal/time_series.rb', line 11 def self.from(year, month, day) TimeSeries.new to_date(year, month, day) end |
Instance Method Details
#[](date) ⇒ Object
39 40 41 42 43 |
# File 'lib/asdrubal/time_series.rb', line 39 def [](date) raise Exception.new('Out of range') unless include?(date) refresh_cache at(date).value end |
#[]=(date, value) ⇒ Object
45 46 47 48 49 |
# File 'lib/asdrubal/time_series.rb', line 45 def []=(date, value) raise Exception.new('Out of range') unless include?(date) reset_cache @dates[date] = value end |
#at(date) ⇒ Object
34 35 36 37 |
# File 'lib/asdrubal/time_series.rb', line 34 def at(date) refresh_cache @cache[date] end |
#each ⇒ Object
24 25 26 27 28 |
# File 'lib/asdrubal/time_series.rb', line 24 def each @span.step(@step).each do |date| yield date, self[date] end end |
#include?(date) ⇒ Boolean
30 31 32 |
# File 'lib/asdrubal/time_series.rb', line 30 def include?(date) @span.include?(date) end |
#step(days) ⇒ Object
19 20 21 22 |
# File 'lib/asdrubal/time_series.rb', line 19 def step(days) @step = days self end |
#to(year, month, day) ⇒ Object
15 16 17 |
# File 'lib/asdrubal/time_series.rb', line 15 def to(year, month, day) TimeSeries.new @span.first, self.class.to_date(year, month, day) end |