Class: Map::Tube::MapLoader
- Inherits:
-
Object
- Object
- Map::Tube::MapLoader
- Defined in:
- lib/map/tube/map_loader.rb
Instance Attribute Summary collapse
-
#city ⇒ Object
Returns the value of attribute city.
-
#map_path ⇒ Object
Returns the value of attribute map_path.
Instance Method Summary collapse
-
#initialize(city_name, map_path = nil) ⇒ MapLoader
constructor
A new instance of MapLoader.
- #read ⇒ Object
Constructor Details
#initialize(city_name, map_path = nil) ⇒ MapLoader
Returns a new instance of MapLoader.
6 7 8 9 10 11 12 13 |
# File 'lib/map/tube/map_loader.rb', line 6 def initialize(city_name, map_path=nil) @city = city_name.split(' ').join("_") if map_path # Always trust the path if it comes from the user @map_path = map_path else @map_path = set_path_for_city end end |
Instance Attribute Details
#city ⇒ Object
Returns the value of attribute city.
4 5 6 |
# File 'lib/map/tube/map_loader.rb', line 4 def city @city end |
#map_path ⇒ Object
Returns the value of attribute map_path.
4 5 6 |
# File 'lib/map/tube/map_loader.rb', line 4 def map_path @map_path end |
Instance Method Details
#read ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/map/tube/map_loader.rb', line 15 def read if File.exist?(@map_path) Parser.new(File.open(@map_path)).parse! else raise Map::Tube::Exceptions::CityException, "Map for #{@city} does not exist" end end |