Class: Bahn::Station
- Inherits:
-
Object
- Object
- Bahn::Station
- Defined in:
- lib/bahn.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
The numeric ID of this station.
Class Method Summary collapse
-
.find(id_or_type, opts = {}) ⇒ Object
Finds and returns one or many Station objects.
Instance Method Summary collapse
-
#departures(opts = {}) ⇒ Object
Returns an Enumerable listing of Stop objects for all services departing from this station.
-
#initialize(opts) ⇒ Station
constructor
:nodoc:.
-
#name ⇒ Object
Returns the station name.
-
#x_coord ⇒ Object
Returns the X coordinate of the station; appears to be a WGS84 longitude in units of 10^-6 degrees.
-
#y_coord ⇒ Object
Returns the Y coordinate of the station; appears to be a WGS84 latitude in units of 10^-6 degrees.
Constructor Details
#initialize(opts) ⇒ Station
:nodoc:
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/bahn.rb', line 51 def initialize(opts) # :nodoc: if opts[:autocomplete_result] populate_from_autocomplete_result(opts[:autocomplete_result]) else @id = opts[:id].to_i @name = opts[:name] @x_coord = opts[:x_coord] @y_coord = opts[:y_coord] end end |
Instance Attribute Details
#id ⇒ Object (readonly)
The numeric ID of this station.
63 64 65 |
# File 'lib/bahn.rb', line 63 def id @id end |
Class Method Details
.find(id_or_type, opts = {}) ⇒ Object
Finds and returns one or many Station objects. Invoked through one of the following forms:
-
Bahn::Station.find(id)
- returns the Station with the given ID -
Bahn::Station.find(:first, :name => name)
- returns the first station matching name -
Bahn::Station.find(:all, :name => name)
- returns an array of all stations matching name
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/bahn.rb', line 38 def self.find(id_or_type, opts = {}) case id_or_type when :first query = autocomplete_query(opts[:name]) query.size ? self.new(:autocomplete_result => query.first) : nil when :all query = autocomplete_query(opts[:name]) query.collect {|result| self.new(:autocomplete_result => result)} else # assume a numeric ID self.new(:id => id_or_type) end end |
Instance Method Details
#departures(opts = {}) ⇒ Object
Returns an Enumerable listing of Stop objects for all services departing from this station. The list can be filtered by transport type through the following options:
-
:include
- One of the symbols :ice, :ic_ec, :ir, :regional, :urban, :bus, :boat, :subway, :tram, or an array of them, to determine which transport types should be included in the list -
:exclude
- Specifies one or more of the above transport types to be excluded from the results.
87 88 89 |
# File 'lib/bahn.rb', line 87 def departures(opts = {}) DepartureBoard.new(self, opts) end |
#name ⇒ Object
Returns the station name.
66 67 68 69 |
# File 'lib/bahn.rb', line 66 def name fetch_autocomplete_result if @name.nil? @name end |
#x_coord ⇒ Object
Returns the X coordinate of the station; appears to be a WGS84 longitude in units of 10^-6 degrees.
72 73 74 75 |
# File 'lib/bahn.rb', line 72 def x_coord fetch_autocomplete_result if @x_coord.nil? @x_coord end |
#y_coord ⇒ Object
Returns the Y coordinate of the station; appears to be a WGS84 latitude in units of 10^-6 degrees.
78 79 80 81 |
# File 'lib/bahn.rb', line 78 def y_coord fetch_autocomplete_result if @y_coord.nil? @y_coord end |