Class: Waqi::StationData

Inherits:
Object
  • Object
show all
Defined in:
lib/waqi/models/station_data.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ StationData

Returns a new instance of StationData.



22
23
24
25
26
27
28
29
30
# File 'lib/waqi/models/station_data.rb', line 22

def initialize(args = {})
  @aqi = args[:aqi]
  @idx = args[:idx]
  @uid = args[:uid]
  @station = args[:station]
  @dominant_pollution = args[:dominant_pollution]
  @weather_condition = args[:weather_condition]
  @timestamp = args[:timestamp]
end

Instance Attribute Details

#aqiObject (readonly)

Returns the value of attribute aqi.



3
4
5
# File 'lib/waqi/models/station_data.rb', line 3

def aqi
  @aqi
end

#dominant_pollutionObject (readonly)

Returns the value of attribute dominant_pollution.



3
4
5
# File 'lib/waqi/models/station_data.rb', line 3

def dominant_pollution
  @dominant_pollution
end

#idxObject (readonly)

Returns the value of attribute idx.



3
4
5
# File 'lib/waqi/models/station_data.rb', line 3

def idx
  @idx
end

#stationObject (readonly)

Returns the value of attribute station.



3
4
5
# File 'lib/waqi/models/station_data.rb', line 3

def station
  @station
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



3
4
5
# File 'lib/waqi/models/station_data.rb', line 3

def timestamp
  @timestamp
end

#uidObject (readonly)

Returns the value of attribute uid.



3
4
5
# File 'lib/waqi/models/station_data.rb', line 3

def uid
  @uid
end

#weather_conditionObject (readonly)

Returns the value of attribute weather_condition.



3
4
5
# File 'lib/waqi/models/station_data.rb', line 3

def weather_condition
  @weather_condition
end

Class Method Details

.parse(data) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/waqi/models/station_data.rb', line 4

def self.parse(data)
  wheather_condition = data[:iaqi] ? WeatherCondition.new(data[:iaqi]) : nil
  station = data[:station] ? Station.parse(data[:station]) : Station.parse(data)
  new(
    aqi: data[:aqi],
    idx: data[:idx],
    uid: data[:uid],
    dominant_pollution: data[:dominentpol],
    station: station,
    weather_condition: wheather_condition,
    timestamp: parse_time(data[:time])
  )
end

.parse_time(time_data) ⇒ Object



18
19
20
# File 'lib/waqi/models/station_data.rb', line 18

def self.parse_time(time_data)
  DateTime.parse("#{time_data[:s] || time_data[:stime]}#{time_data[:tz]}") rescue nil
end