class PM25::Base

Constants

ATTRS

Public Class Methods

all() click to toggle source
# File lib/pm25/base.rb, line 16
def self.all
  get.select{|x| x.key? 'AQI'}.map(&method(:clean_up))
end
clean_up(data) click to toggle source
# File lib/pm25/base.rb, line 50
def self.clean_up(data)
  parse slice(data)
end
get() click to toggle source
# File lib/pm25/base.rb, line 12
def self.get
  Hash.from_xml(HTTParty.get(url).body)['rss']['channel']['item']
end
last() click to toggle source
# File lib/pm25/base.rb, line 20
def self.last
  clean_up(get.find{|x| x.key? 'AQI'})
end
Also aliased as: latest
latest()
Alias for: last
parse(data) click to toggle source
# File lib/pm25/base.rb, line 41
def self.parse(data)
  parsed_data = {}
  parsed_data['Conc'] = data['Conc'].to_f
  parsed_data['AQI'] = data['AQI'].to_i
  parsed_data['Desc'] = data['Desc'].to_s
  parsed_data['ReadingDateTime'] = DateTime.strptime(data['ReadingDateTime'], '%m/%d/%Y %I:%M:%S %p')
  parsed_data
end
slice(data) click to toggle source
# File lib/pm25/base.rb, line 37
def self.slice(data)
  data.slice(*ATTRS)
end
uri() click to toggle source
# File lib/pm25/base.rb, line 27
def self.uri
  raise NotImplementedError, "Please set value for 'city_id' class attributes in '#{self.name}' class." unless self.city_id
  self.base_uri.path = "/web/rss/1/#{self.city_id.to_s}.xml"
  self.base_uri
end
url() click to toggle source
# File lib/pm25/base.rb, line 33
def self.url
  uri.to_s
end