Class: TspRunner::LocationHash
- Inherits:
-
Object
- Object
- TspRunner::LocationHash
- Defined in:
- lib/tsp_runner/location_hash.rb
Instance Attribute Summary collapse
-
#locations ⇒ Object
readonly
Returns the value of attribute locations.
Class Method Summary collapse
Instance Method Summary collapse
- #<<(location) ⇒ Object
- #[](location_name) ⇒ Object
-
#initialize ⇒ LocationHash
constructor
A new instance of LocationHash.
- #location_names ⇒ Object
Constructor Details
#initialize ⇒ LocationHash
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
#locations ⇒ Object (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_names ⇒ Object
26 27 28 |
# File 'lib/tsp_runner/location_hash.rb', line 26 def location_names locations.keys end |