Class: Bahn::Station

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Station

:nodoc:



52
53
54
55
56
57
58
59
60
61
# File 'lib/bahn.rb', line 52

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

#idObject (readonly)

The numeric ID of this station.



64
65
66
# File 'lib/bahn.rb', line 64

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



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/bahn.rb', line 39

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.



88
89
90
# File 'lib/bahn.rb', line 88

def departures(opts = {})
	DepartureBoard.new(self, opts)
end

#nameObject

Returns the station name.



67
68
69
70
# File 'lib/bahn.rb', line 67

def name
	fetch_autocomplete_result if @name.nil?
	@name
end

#x_coordObject

Returns the X coordinate of the station; appears to be a WGS84 longitude in units of 10^-6 degrees.



73
74
75
76
# File 'lib/bahn.rb', line 73

def x_coord
	fetch_autocomplete_result if @x_coord.nil?
	@x_coord
end

#y_coordObject

Returns the Y coordinate of the station; appears to be a WGS84 latitude in units of 10^-6 degrees.



79
80
81
82
# File 'lib/bahn.rb', line 79

def y_coord
	fetch_autocomplete_result if @y_coord.nil?
	@y_coord
end