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?'
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.
19 20 21 22 23 24 |
# File 'lib/trafikanten_travel/route.rb', line 19 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
13 14 15 16 17 |
# File 'lib/trafikanten_travel/route.rb', line 13 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 error-checking.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/trafikanten_travel/route.rb', line 27 def parse doc = TrafikantenTravel::Utils.fetch(BASE_URL + query_string) if doc =~ /Ingen forbindelse funnet eller ingen stoppesteder funnet/ return {} end if doc =~ /Trafikanten - Feilmelding/ doc =~ /<p>(.+)<\/p>/ raise Error.new($1) end if doc =~ /Microsoft VBScript runtime/ raise BadRequest end do_parse(doc) end |