Class: Accuweather::Conditions::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/accuweather/conditions/parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Parser

Returns a new instance of Parser.



4
5
6
# File 'lib/accuweather/conditions/parser.rb', line 4

def initialize(response)
  @doc = Nokogiri::XML.parse(response)
end

Instance Method Details

#currentObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/accuweather/conditions/parser.rb', line 31

def current
  current = @doc.css('currentconditions').first
  Accuweather::Conditions::Current.new(url: current.css('url').text,
                                       observation_time: current.css('observationtime').text,
                                       pressure: current.css('pressure').text,
                                       temperature: current.css('temperature').text,
                                       real_feel: current.css('realfeel').text,
                                       humidity: current.css('humidity').text,
                                       weather_text: current.css('weathertext').text,
                                       weather_icon: current.css('weathericon').text,
                                       wind_gusts: current.css('windgusts').text,
                                       wind_speed: current.css('windspeed').text,
                                       wind_direction: current.css('winddirection').text,
                                       visibility: current.css('visibility').text,
                                       precip: current.css('precip').text,
                                       uv_index: current.css('uvindex').text,
                                       dewpoint: current.css('dewpoint').text,
                                       cloud_cover: current.css('cloudcover').text,
  )
end

#localObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/accuweather/conditions/parser.rb', line 17

def local
  local = @doc.css('local').first
  Accuweather::Conditions::Local.new(city: local.css('city').text,
                                     state: local.css('state').text,
                                     latitude: local.css('lat').text,
                                     longitude: local.css('lon').text,
                                     time: local.css('time').text,
                                     time_zone: local.css('timeZone').text,
                                     obs_daylight: local.css('obsDaylight').text.strip,
                                     current_gmt_offset: local.css('currentGmtOffset').text,
                                     time_zone_abbreviation: local.css('timeZoneAbbreviation').text,
  )
end

#unitsObject



8
9
10
11
12
13
14
15
# File 'lib/accuweather/conditions/parser.rb', line 8

def units
  units = @doc.css('units').first
  Accuweather::Conditions::Units.new(temperature: units.css('temp').text,
                                     distance: units.css('dist').text,
                                     speed: units.css('speed').text,
                                     pressure: units.css('pres').text,
                                     precipitation: units.css('prec').text)
end