Class: Forecast::IO::Cache::ForecastData

Inherits:
Struct
  • Object
show all
Defined in:
lib/forecast_io/cache/forecast_data.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#humidityObject

Returns the value of attribute humidity

Returns:

  • (Object)

    the current value of humidity



4
5
6
# File 'lib/forecast_io/cache/forecast_data.rb', line 4

def humidity
  @humidity
end

#positionObject

Returns the value of attribute position

Returns:

  • (Object)

    the current value of position



4
5
6
# File 'lib/forecast_io/cache/forecast_data.rb', line 4

def position
  @position
end

#pressureObject

Returns the value of attribute pressure

Returns:

  • (Object)

    the current value of pressure



4
5
6
# File 'lib/forecast_io/cache/forecast_data.rb', line 4

def pressure
  @pressure
end

#temperatureObject

Returns the value of attribute temperature

Returns:

  • (Object)

    the current value of temperature



4
5
6
# File 'lib/forecast_io/cache/forecast_data.rb', line 4

def temperature
  @temperature
end

#timeObject

Returns the value of attribute time

Returns:

  • (Object)

    the current value of time



4
5
6
# File 'lib/forecast_io/cache/forecast_data.rb', line 4

def time
  @time
end

#visibilityObject

Returns the value of attribute visibility

Returns:

  • (Object)

    the current value of visibility



4
5
6
# File 'lib/forecast_io/cache/forecast_data.rb', line 4

def visibility
  @visibility
end

#wind_bearingObject

Returns the value of attribute wind_bearing

Returns:

  • (Object)

    the current value of wind_bearing



4
5
6
# File 'lib/forecast_io/cache/forecast_data.rb', line 4

def wind_bearing
  @wind_bearing
end

#wind_speedObject

Returns the value of attribute wind_speed

Returns:

  • (Object)

    the current value of wind_speed



4
5
6
# File 'lib/forecast_io/cache/forecast_data.rb', line 4

def wind_speed
  @wind_speed
end

Class Method Details

.generate(lat, lon, forecast) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/forecast_io/cache/forecast_data.rb', line 7

def self.generate lat, lon, forecast
  new.tap do |data|
    data.position = [lon,lat].map(&:to_f)
    data.time             = forecast['time']
    data.wind_speed       = forecast['windSpeed']
    data.wind_bearing     = forecast['windBearing']
    data.humidity         = forecast['humidity']
    data.pressure         = forecast['pressure']
    data.visibility       = forecast['visibility']
    data.temperature      = forecast['temperature']
  end
end

Instance Method Details

#to_jsonObject



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/forecast_io/cache/forecast_data.rb', line 20

def to_json
  {
    time:         time,
    latitude:     position[1],
    longitude:    position[0],
    wind_speed:   wind_speed,
    wind_bearing: wind_bearing,
    humidity:     humidity,
    pressure:     pressure,
    visibility:   visibility,
    temperature:  temperature
  }
end