Class: Skanetrafiken::QueryStation

Inherits:
Object
  • Object
show all
Defined in:
lib/skanetrafiken/query_station.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ QueryStation

Returns a new instance of QueryStation.



6
7
8
# File 'lib/skanetrafiken/query_station.rb', line 6

def initialize opts={}
    @xmltojson = opts[:xml_to_json] || XmlToJson.new()
end

Instance Method Details

#get_stations(html) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/skanetrafiken/query_station.rb', line 12

def get_stations(html)
    doc = REXML::Document.new(html)
    el = []
    v = doc.elements["soap:Envelope/soap:Body/GetStartEndPointResponse/GetStartEndPointResult/StartPoints"]
    v.elements.each("Point") { |j|
        el.push(Point.new(
          j.elements["Name"].text,
          j.elements["Id"].text,
          $point_string_totype[j.elements["Type"].text]
        ))
    }
    return el
end

#json(html) ⇒ Object



25
26
27
28
29
# File 'lib/skanetrafiken/query_station.rb', line 25

def json(html)
  doc = REXML::Document.new(html)
  xml = doc.elements["soap:Envelope/soap:Body/GetStartEndPointResponse/GetStartEndPointResult/StartPoints"]
  return @xmltojson.convert( xml.to_s )
end

#render_url(name) ⇒ Object



9
10
11
# File 'lib/skanetrafiken/query_station.rb', line 9

def render_url(name)
    return "http://www.labs.skanetrafiken.se/v2.2/querystation.asp?inpPointfr=#{URI.escape(name)}"
end