Class: TrafikantenTravel::Route
- Inherits:
-
Object
- Object
- TrafikantenTravel::Route
- Includes:
- Utils
- Defined in:
- lib/trafikanten_travel/route.rb
Defined Under Namespace
Classes: Step
Constant Summary collapse
- BASE_URL =
'http://m.trafikanten.no/BetRes.asp?'
- NOTFOUND =
/Ingen forbindelse funnet eller ingen stoppesteder funnet|Ingen turer ankommer ankomststed|Ingen turer utgår fra avgangsted/u
Instance Attribute Summary collapse
-
#duration ⇒ Object
Returns the value of attribute duration.
-
#steps ⇒ Object
Returns the value of attribute steps.
Class Method Summary collapse
-
.find(from, to, time = TrafikantenTravel::Utils.time_class.now) ⇒ Object
Searches and returns a Route object for the found trip.
Instance Method Summary collapse
-
#initialize(from, to, time = TrafikantenTravel::Utils.time_class.now) ⇒ Route
constructor
A new instance of Route.
-
#parse ⇒ Object
Parse the received HTML.
Methods included from Utils
Constructor Details
#initialize(from, to, time = TrafikantenTravel::Utils.time_class.now) ⇒ Route
Returns a new instance of Route.
20 21 22 23 24 25 |
# File 'lib/trafikanten_travel/route.rb', line 20 def initialize(from, to, time = TrafikantenTravel::Utils.time_class.now) @from = from @to = to @time = time @steps = [] end |
Instance Attribute Details
#duration ⇒ Object
Returns the value of attribute duration.
9 10 11 |
# File 'lib/trafikanten_travel/route.rb', line 9 def duration @duration end |
#steps ⇒ Object
Returns the value of attribute steps.
9 10 11 |
# File 'lib/trafikanten_travel/route.rb', line 9 def steps @steps end |
Class Method Details
.find(from, to, time = TrafikantenTravel::Utils.time_class.now) ⇒ Object
Searches and returns a Route object for the found trip
14 15 16 17 18 |
# File 'lib/trafikanten_travel/route.rb', line 14 def self.find(from, to, time = TrafikantenTravel::Utils.time_class.now) route = Route.new(from, to, time) route.parse route end |
Instance Method Details
#parse ⇒ Object
Parse the received HTML. First try some simple error-checking.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/trafikanten_travel/route.rb', line 28 def parse doc = TrafikantenTravel::Utils.fetch(BASE_URL + query_string) case doc when NOTFOUND return {} when /Trafikanten - Feilmelding/ doc =~ /<p>(.+)<\/p>/ raise Error.new($1) when /Microsoft VBScript runtime/ raise BadRequest end do_parse(doc) end |