Class: Skanetrafiken::GetJourney
- Inherits:
-
Object
- Object
- Skanetrafiken::GetJourney
- Defined in:
- lib/skanetrafiken/get_journey.rb
Instance Method Summary collapse
- #get_times(html) ⇒ Object
-
#initialize(opts = {}) ⇒ GetJourney
constructor
A new instance of GetJourney.
- #json(html) ⇒ Object
- #render_url(pointFrom, pointTo, lastStart) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ GetJourney
Returns a new instance of GetJourney.
3 4 5 6 |
# File 'lib/skanetrafiken/get_journey.rb', line 3 def initialize opts = {} @uri = UriHelper.new @xmltojson = opts[:xml_to_json] || XmlToJson.new() end |
Instance Method Details
#get_times(html) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/skanetrafiken/get_journey.rb', line 20 def get_times(html) doc = REXML::Document.new(html) el = [] doc.elements["soap:Envelope/soap:Body/GetJourneyResponse/GetJourneyResult/Journeys"]\ .elements.each("Journey") { |j| el.push(j.elements["DepDateTime"].text) } return el end |
#json(html) ⇒ Object
29 30 31 32 33 |
# File 'lib/skanetrafiken/get_journey.rb', line 29 def json(html) doc = REXML::Document.new(html) xml = doc.elements["soap:Envelope/soap:Body/GetJourneyResponse/GetJourneyResult/Journeys"] return @xmltojson.convert( xml.to_s ) end |
#render_url(pointFrom, pointTo, lastStart) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/skanetrafiken/get_journey.rb', line 7 def render_url(pointFrom,pointTo,lastStart) lastStartText = lastStart.strftime("%Y-%m-%d %H:%M") to = pointTo.render() from = pointFrom.render() parameters = { :cmdaction =>:next, :selPointFr =>pointFrom.render(), :selPointTo =>pointTo.render(), :LastStart =>lastStartText } return "http://www.labs.skanetrafiken.se/v2.2/resultspage.asp?" + @uri.parameters_from_hash(parameters) end |