Sha256: b8ed3b29f8b4b1dba109e0550b7b12ac56bad7ce50f3a7f4f1b285189cc3ea88

Contents?: true

Size: 670 Bytes

Versions: 6

Compression:

Stored size: 670 Bytes

Contents

class Forecast
  class Collection < Array
    def select_date(date)
      result = nil
      date_forecasts = self.select do |obj|
        obj.date.to_date == date.to_date
      end
      if date_forecasts.length == 0
        return nil
      else
        hour_forecasts = date_forecasts.select do |obj|
          obj.date.hour == obj.date.hour
        end
        if hour_forecasts.length > 0
          return hour_forecasts.first
        end
        return date_forecasts.first
      end
      return nil
      
    end
    
    private 
      def seconds_between(date1, date2)
        ((Time.parse(date1.to_s) - Time.parse(date2.to_s)) / 3600).abs
      end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
forecast-0.0.7 lib/forecast/collection.rb
forecast-0.0.6 lib/forecast/collection.rb
forecast-0.0.5 lib/forecast/collection.rb
forecast-0.0.4 lib/forecast/collection.rb
forecast-0.0.3 lib/forecast/collection.rb
forecast-0.0.2 lib/forecast/collection.rb