Class: Evestatic::Station
- Inherits:
-
Object
- Object
- Evestatic::Station
- Defined in:
- lib/evestatic/stations.rb
Constant Summary collapse
- @@stations =
{}
Instance Attribute Summary collapse
-
#region_id ⇒ Object
Returns the value of attribute region_id.
-
#solarsystem_id ⇒ Object
Returns the value of attribute solarsystem_id.
-
#station_id ⇒ Object
Returns the value of attribute station_id.
-
#station_name ⇒ Object
Returns the value of attribute station_name.
Class Method Summary collapse
- .[](key = nil) ⇒ Object
- .by_id(id = nil) ⇒ Object
- .by_name(name) ⇒ Object
- .find_by_name(name) ⇒ Object
- .load! ⇒ Object
- .load_from_file(path) ⇒ Object
Instance Method Summary collapse
-
#initialize(station_id, station_name, solarsystem_id, region_id) ⇒ Station
constructor
A new instance of Station.
Constructor Details
#initialize(station_id, station_name, solarsystem_id, region_id) ⇒ Station
Returns a new instance of Station.
45 46 47 48 49 50 |
# File 'lib/evestatic/stations.rb', line 45 def initialize(station_id, station_name,solarsystem_id,region_id) self.station_id = station_id self.station_name = station_name self.solarsystem_id = solarsystem_id self.region_id = region_id end |
Instance Attribute Details
#region_id ⇒ Object
Returns the value of attribute region_id.
6 7 8 |
# File 'lib/evestatic/stations.rb', line 6 def region_id @region_id end |
#solarsystem_id ⇒ Object
Returns the value of attribute solarsystem_id.
6 7 8 |
# File 'lib/evestatic/stations.rb', line 6 def solarsystem_id @solarsystem_id end |
#station_id ⇒ Object
Returns the value of attribute station_id.
6 7 8 |
# File 'lib/evestatic/stations.rb', line 6 def station_id @station_id end |
#station_name ⇒ Object
Returns the value of attribute station_name.
6 7 8 |
# File 'lib/evestatic/stations.rb', line 6 def station_name @station_name end |
Class Method Details
.[](key = nil) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/evestatic/stations.rb', line 25 def self.[](key=nil) unless key @@stations else @@stations[key] end end |
.by_id(id = nil) ⇒ Object
33 34 35 |
# File 'lib/evestatic/stations.rb', line 33 def self.by_id(id=nil) Station[id] end |
.by_name(name) ⇒ Object
37 38 39 |
# File 'lib/evestatic/stations.rb', line 37 def self.by_name(name) @@stations.values.collect { |v| v if v.station_name.include? name }.compact[0] end |
.find_by_name(name) ⇒ Object
41 42 43 |
# File 'lib/evestatic/stations.rb', line 41 def self.find_by_name(name) @@stations.values.collect { |v| v if v.station_name.include? name }.compact end |
.load! ⇒ Object
10 11 12 |
# File 'lib/evestatic/stations.rb', line 10 def self.load! Station.load_from_file(File.("../../../data/staStations.csv", __FILE__)) end |
.load_from_file(path) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/evestatic/stations.rb', line 14 def self.load_from_file(path) begin CSV.foreach(path, {col_sep: ";", headers: true}) do |row| @@stations[row[0].to_i] = self.new(row[0].to_i, row[11], row[9].to_i, row[10].to_i) end rescue CSV::MalformedCSVError #trololol do nothing, we have all data, dont care if the newlines are windows mess or whatever end end |