Class: Barometer::Weather

Inherits:
Object
  • Object
show all
Defined in:
lib/barometer/weather.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(units = :metric) ⇒ Weather

Returns a new instance of Weather.



6
7
8
9
# File 'lib/barometer/weather.rb', line 6

def initialize(units=:metric)
  @units = units
  @responses = []
end

Instance Attribute Details

#end_atObject

Returns the value of attribute end_at.



4
5
6
# File 'lib/barometer/weather.rb', line 4

def end_at
  @end_at
end

#responsesObject

Returns the value of attribute responses.



3
4
5
# File 'lib/barometer/weather.rb', line 3

def responses
  @responses
end

#start_atObject

Returns the value of attribute start_at.



4
5
6
# File 'lib/barometer/weather.rb', line 4

def start_at
  @start_at
end

Instance Method Details

#currentObject



19
20
21
# File 'lib/barometer/weather.rb', line 19

def current
  successful_responses.first.current if successful_responses.any?
end

#dew_pointObject



40
# File 'lib/barometer/weather.rb', line 40

def dew_point; average(:dew_point, Data::Temperature); end

#for(query) ⇒ Object



35
36
37
# File 'lib/barometer/weather.rb', line 35

def for(query)
  successful_responses.first.for(query) if successful_responses.any?
end

#forecastObject



23
24
25
# File 'lib/barometer/weather.rb', line 23

def forecast
  successful_responses.first.forecast if successful_responses.any?
end

#heat_indexObject



41
# File 'lib/barometer/weather.rb', line 41

def heat_index; average(:heat_index, Data::Temperature); end

#humidityObject



46
# File 'lib/barometer/weather.rb', line 46

def humidity; average(:humidity); end

#pressureObject



43
# File 'lib/barometer/weather.rb', line 43

def pressure; average(:pressure, Data::Pressure); end

#source(source) ⇒ Object



11
12
13
# File 'lib/barometer/weather.rb', line 11

def source(source)
  responses.detect{|response| response.source == source}
end

#success?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/barometer/weather.rb', line 15

def success?
  responses.any?(&:success?)
end

#temperatureObject



39
# File 'lib/barometer/weather.rb', line 39

def temperature; average(:temperature, Data::Temperature); end

#todayObject



27
28
29
# File 'lib/barometer/weather.rb', line 27

def today
  successful_responses.first.forecast[0] if successful_responses.any?
end

#tomorrowObject



31
32
33
# File 'lib/barometer/weather.rb', line 31

def tomorrow
  successful_responses.first.forecast[1] if successful_responses.any?
end

#visibilityObject



44
# File 'lib/barometer/weather.rb', line 44

def visibility; average(:visibility, Data::Distance); end

#windObject



45
# File 'lib/barometer/weather.rb', line 45

def wind; average(:wind, Data::Vector); end

#wind_chillObject



42
# File 'lib/barometer/weather.rb', line 42

def wind_chill; average(:wind_chill, Data::Temperature); end