Class: WeatherSage::Weather::Station

Inherits:
BaseObject show all
Defined in:
lib/weather-sage/weather/station.rb

Overview

Thin wrapper around weather station.

Instance Attribute Summary collapse

Attributes inherited from BaseObject

#cache

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ctx, id, name, x, y, elevation, time_zone) ⇒ Station

Create a new station instance.



26
27
28
29
30
31
32
33
34
# File 'lib/weather-sage/weather/station.rb', line 26

def initialize(ctx, id, name, x, y, elevation, time_zone)
  @ctx = ctx
  @id = id
  @name = name
  @x = x
  @y = y
  @elevation = elevation
  @time_zone = time_zone
end

Instance Attribute Details

#elevationObject (readonly)

Returns the value of attribute elevation.



5
6
7
# File 'lib/weather-sage/weather/station.rb', line 5

def elevation
  @elevation
end

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/weather-sage/weather/station.rb', line 5

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/weather-sage/weather/station.rb', line 5

def name
  @name
end

#time_zoneObject (readonly)

Returns the value of attribute time_zone.



5
6
7
# File 'lib/weather-sage/weather/station.rb', line 5

def time_zone
  @time_zone
end

#xObject (readonly)

Returns the value of attribute x.



5
6
7
# File 'lib/weather-sage/weather/station.rb', line 5

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



5
6
7
# File 'lib/weather-sage/weather/station.rb', line 5

def y
  @y
end

Class Method Details

.from_json(ctx, row) ⇒ Object

Create a new Station from the given Context ctx and the JSON data row.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/weather-sage/weather/station.rb', line 11

def self.from_json(ctx, row)
  new(
    ctx,
    row['properties']['stationIdentifier'],
    row['properties']['name'],
    row['geometry']['coordinates'][0],
    row['geometry']['coordinates'][1],
    row['properties']['elevation']['value'],
    row['properties']['timeZone']
  )
end

Instance Method Details

#latest_observationsObject

Return a hash of the latest observations from this station.



39
40
41
42
# File 'lib/weather-sage/weather/station.rb', line 39

def latest_observations
  path = 'stations/%s/observations/latest' % [@id]
  get(path)['properties']
end