Class: Map::Tube::MapLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/map/tube/map_loader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#cityObject

Returns the value of attribute city.



4
5
6
# File 'lib/map/tube/map_loader.rb', line 4

def city
  @city
end

#map_pathObject

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

#readObject



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