Class: Bahn::Station

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json = {}) ⇒ Station

Returns a new instance of Station.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/bahn/bahn_station.rb', line 5

def initialize json={}		
	self.name = json["value"].to_s.gsub("(S-Bahn)", "(S)") unless json["value"].nil?
	
	if json[:do_load]
		station = Agent.new.find_station(name) if json[:load] == :station
		station = Agent.new.find_address(name) if json[:load] == :foot
	end
	
	if station.nil?
		self.lat = json["ycoord"].insert(-7, ".") unless json["ycoord"].nil?
		self.lon = json["xcoord"].insert(-7, ".") unless json["xcoord"].nil?
	else
		self.lat = station.lat
		self.lon = station.lon
	end
end

Instance Attribute Details

#distanceObject

Returns the value of attribute distance.



3
4
5
# File 'lib/bahn/bahn_station.rb', line 3

def distance
  @distance
end

#latObject

Returns the value of attribute lat.



3
4
5
# File 'lib/bahn/bahn_station.rb', line 3

def lat
  @lat
end

#lonObject

Returns the value of attribute lon.



3
4
5
# File 'lib/bahn/bahn_station.rb', line 3

def lon
  @lon
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/bahn/bahn_station.rb', line 3

def name
  @name
end

#station_typeObject

Returns the value of attribute station_type.



3
4
5
# File 'lib/bahn/bahn_station.rb', line 3

def station_type
  @station_type
end

Instance Method Details

#==(other) ⇒ Object



32
33
34
35
# File 'lib/bahn/bahn_station.rb', line 32

def == other
	return false if other.nil?
	remove_parenthesis(other.name) == remove_parenthesis(name)
end

#to_coordinatesObject Also known as: coordinates



27
28
29
# File 'lib/bahn/bahn_station.rb', line 27

def to_coordinates
	[lat, lon]
end

#to_sObject



22
23
24
25
# File 'lib/bahn/bahn_station.rb', line 22

def to_s
                return "#{self.name}" if (self.lat.nil? || self.lon.nil?)
                return "#{self.name} (#{self.lat},#{self.lon})"
end