Method: Weather::Actions#conditions

Defined in:
lib/weather/actions.rb

#conditions(location) ⇒ Hash<Symbol, Object>

Gets weather conditions for the location.

Parameters:

  • location (String)

    The place to get the weather report for.

Returns:

  • (Hash<Symbol, Object>)

    A hash containing strings of relevant weather information. It contains the following keys:

    • ‘:full_name` (`String`) — The full name of the location

    • ‘:city_name` (`String`) — The name of the city

    • ‘:state_abbreviation` (`String`) — The abbreviation for the state (or national equivalent)

    • ‘:state_name` (`String`) — The name of the state (or national equivalent)

    • ‘:country` (`String`) — The name of the country

    • ‘:zip_code` (`Integer`) — The zip code for this location

    • ‘:updated` (`String`) — A string describing the date for when this data was last updated.

    • ‘:weather` (`String`) — A brief description of the current weather conditions in this location (e.g., Partly

    Cloudy)

    • ‘:formatted_temperature` (`String`) — The formatted temperature as provided by the API. It does not contain °

    symbols. Its format is “XX F (YY C)”

    • ‘:temperature_f` (`Float`) — The current temperature in fahrenheit

    • ‘:temperature_c` (`Float`) — The current temperature in celsius

    • ‘:humidity` (`Integer`) — The humidity percentage

    • ‘:formatted_wind` (`String`) — A brief description of the current wind conditions (e.g., Calm)

    • ‘:wind_direction` (`String`) — The direction (East, West, etc.) that the wind is blowing

    • ‘:wind_degrees` (`Integer`) — The angle of the wind

    • ‘:wind_speed` (`Float`) — The speed of the wind in miles per hour

    • ‘:wind_gust_speed` (`Integer`) — The speed of the gusts of wind in miles per hour

    • ‘:formatted_feelslike` (`String`) — The formatted string for the “feels like” temperature data as provided

    by the API. See :formatted_temperature for the format.

    • ‘:feelslike_f` (`Integer`) — The temperature that it feels like (not always the same as the temperature it

    is) in fahrenheit

    • ‘:feelslike_c` (`Integer`) — Like feelslike_f but in celsius



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/weather/actions.rb', line 95

def conditions(location)
  response = get('conditions', location)
  current_observation = response['current_observation']
  display_location = current_observation['display_location']

  ret = {
    full_name: display_location['full'],
    city_name: display_location['city'],
    state_abbreviation: display_location['state'],
    state_name: display_location['state_name'],
    country: display_location['country'],
    zip_code: display_location['zip'].to_i,
    updated: current_observation['observation_time'],
    weather: current_observation['weather'],
    formatted_temperature: current_observation['temperature_string'],
    temperature_f: current_observation['temp_f'],
    temperature_c: current_observation['temp_c'],
    humidity: current_observation['relative_humidity'],
    formatted_wind: current_observation['wind_string'],
    wind_direction: current_observation['wind_dir'],
    wind_degrees: current_observation['wind_degrees'],
    wind_speed: current_observation['wind_mph'],
    wind_gust_speed: current_observation['wind_gust_mph'].to_i,
    formatted_feelslike: current_observation['feelslike_string'],
    feelslike_f: current_observation['feelslike_f'].to_i,
    feelslike_c: current_observation['feelslike_c'].to_i
  }

  ret[:humidity] = ret[:humidity].sub('%', '').to_i

  ret
end