Class: TspRunner::LocationHash

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLocationHash

Returns a new instance of LocationHash.



14
15
16
# File 'lib/tsp_runner/location_hash.rb', line 14

def initialize
  @locations = {}
end

Instance Attribute Details

#locationsObject (readonly)

Returns the value of attribute locations.



3
4
5
# File 'lib/tsp_runner/location_hash.rb', line 3

def locations
  @locations
end

Class Method Details

.from_file(filename) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/tsp_runner/location_hash.rb', line 5

def self.from_file(filename)
  new.tap do |location_hash|
    File.open(filename).each do |line|
      name, lat_str, lon_str = *line.chomp.split(',')
      location_hash << Location.new(name, Float(lat_str), Float(lon_str))
    end
  end
end

Instance Method Details

#<<(location) ⇒ Object



18
19
20
# File 'lib/tsp_runner/location_hash.rb', line 18

def <<(location)
  locations[location.name] = location
end

#[](location_name) ⇒ Object



22
23
24
# File 'lib/tsp_runner/location_hash.rb', line 22

def [](location_name)
  locations[location_name]
end

#location_namesObject



26
27
28
# File 'lib/tsp_runner/location_hash.rb', line 26

def location_names
  locations.keys
end