Class: Barometer::Response::PredictionCollection
- Inherits:
-
Object
- Object
- Barometer::Response::PredictionCollection
- Includes:
- Enumerable
- Defined in:
- lib/barometer/response/prediction_collection.rb
Instance Method Summary collapse
- #<<(prediction) ⇒ Object
- #[](index) ⇒ Object
- #build {|prediction| ... } ⇒ Object
- #each(&block) ⇒ Object
- #for(time) ⇒ Object
-
#initialize(*predictions) ⇒ PredictionCollection
constructor
A new instance of PredictionCollection.
- #size ⇒ Object
Constructor Details
#initialize(*predictions) ⇒ PredictionCollection
Returns a new instance of PredictionCollection.
8 9 10 |
# File 'lib/barometer/response/prediction_collection.rb', line 8 def initialize(*predictions) @predictions = predictions end |
Instance Method Details
#<<(prediction) ⇒ Object
16 17 18 |
# File 'lib/barometer/response/prediction_collection.rb', line 16 def <<(prediction) @predictions << prediction end |
#[](index) ⇒ Object
20 21 22 |
# File 'lib/barometer/response/prediction_collection.rb', line 20 def [](index) index.respond_to?(:to_i) ? @predictions[index] : self.for(index) end |
#build {|prediction| ... } ⇒ Object
41 42 43 44 45 |
# File 'lib/barometer/response/prediction_collection.rb', line 41 def build prediction = Prediction.new yield(prediction) @predictions << prediction end |
#each(&block) ⇒ Object
12 13 14 |
# File 'lib/barometer/response/prediction_collection.rb', line 12 def each(&block) @predictions.each(&block) end |
#for(time) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/barometer/response/prediction_collection.rb', line 28 def for(time) return nil unless size > 0 time = case time when Date Time.utc(time.year,time.month,time.day,12,0,0) else Utils::Time.parse(time) end detect{ |forecast| forecast.covers?(time) } end |
#size ⇒ Object
24 25 26 |
# File 'lib/barometer/response/prediction_collection.rb', line 24 def size @predictions.size end |