Class: Skanetrafiken::GetDepartureArrival
- Inherits:
-
Object
- Object
- Skanetrafiken::GetDepartureArrival
- Defined in:
- lib/skanetrafiken/get_departure_arrival.rb
Instance Method Summary collapse
- #get_lines(html) ⇒ Object
-
#initialize(opts = {}) ⇒ GetDepartureArrival
constructor
A new instance of GetDepartureArrival.
- #json(html) ⇒ Object
- #render_url(point) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ GetDepartureArrival
Returns a new instance of GetDepartureArrival.
3 4 5 |
# File 'lib/skanetrafiken/get_departure_arrival.rb', line 3 def initialize opts={} @xmltojson = opts[:xml_to_json] || XmlToJson.new() end |
Instance Method Details
#get_lines(html) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/skanetrafiken/get_departure_arrival.rb', line 10 def get_lines(html) doc = REXML::Document.new(html) el = [] v = doc.elements["soap:Envelope/soap:Body/GetDepartureArrivalResponse/GetDepartureArrivalResult/Lines"] v.elements.each("Line") { |j| dic = {} $properties_line.each{ |key,value| xval = j.elements[value].text dic[key] = xval #puts "#{key} = #{value} = #{xval}" } #deviation info = j.elements["RealTime/RealTimeInfo"] if info dic[:dep_time_deviation] = info.elements["DepTimeDeviation"].text dic[:dep_deviation_affect] = info.elements["DepDeviationAffect"].text end #<RealTime> #<RealTimeInfo> #<DepTimeDeviation>40</DepTimeDeviation> #<DepDeviationAffect>CRITICAL</DepDeviationAffect> #puts dic.map{ |k,v| "#{k}, #{v}" }.join('; ') el.push(Line.new(dic)) } return el end |
#json(html) ⇒ Object
38 39 40 41 42 |
# File 'lib/skanetrafiken/get_departure_arrival.rb', line 38 def json(html) doc = REXML::Document.new(html) xml = doc.elements["soap:Envelope/soap:Body/GetDepartureArrivalResponse/GetDepartureArrivalResult/Lines"] return @xmltojson.convert( xml.to_s ) end |
#render_url(point) ⇒ Object
6 7 8 |
# File 'lib/skanetrafiken/get_departure_arrival.rb', line 6 def render_url(point) return "http://www.labs.skanetrafiken.se/v2.2/stationresults.asp?selPointFrKey=#{point.id}" end |