Class: Evestatic::ItemType
- Inherits:
-
Object
- Object
- Evestatic::ItemType
- Defined in:
- lib/evestatic/itemtypes.rb
Constant Summary collapse
- @@item_types_by_id =
{}
- @@item_types_by_name =
{}
Instance Attribute Summary collapse
-
#group_id ⇒ Object
Returns the value of attribute group_id.
-
#mass ⇒ Object
Returns the value of attribute mass.
-
#type_id ⇒ Object
Returns the value of attribute type_id.
-
#type_name ⇒ Object
Returns the value of attribute type_name.
-
#volume ⇒ Object
Returns the value of attribute volume.
Class Method Summary collapse
-
.[](key = nil) ⇒ Object
INDEXED BY TYPE_ID! Static::ItemType.type_name => “Tritanium”.
- .by_id(id = nil) ⇒ Object
-
.by_name(key = nil) ⇒ Object
INDEXED BY NAME! Static::ItemType.type_id => 34.
- .load! ⇒ Object
- .load_from_file(path) ⇒ Object
Instance Method Summary collapse
-
#initialize(type_id, group_id, type_name, mass, volume) ⇒ ItemType
constructor
A new instance of ItemType.
Constructor Details
#initialize(type_id, group_id, type_name, mass, volume) ⇒ ItemType
Returns a new instance of ItemType.
51 52 53 54 55 56 57 |
# File 'lib/evestatic/itemtypes.rb', line 51 def initialize(type_id, group_id, type_name, mass, volume) self.type_id = type_id self.group_id = group_id self.type_name = type_name self.mass = mass self.volume = volume end |
Instance Attribute Details
#group_id ⇒ Object
Returns the value of attribute group_id.
6 7 8 |
# File 'lib/evestatic/itemtypes.rb', line 6 def group_id @group_id end |
#mass ⇒ Object
Returns the value of attribute mass.
6 7 8 |
# File 'lib/evestatic/itemtypes.rb', line 6 def mass @mass end |
#type_id ⇒ Object
Returns the value of attribute type_id.
6 7 8 |
# File 'lib/evestatic/itemtypes.rb', line 6 def type_id @type_id end |
#type_name ⇒ Object
Returns the value of attribute type_name.
6 7 8 |
# File 'lib/evestatic/itemtypes.rb', line 6 def type_name @type_name end |
#volume ⇒ Object
Returns the value of attribute volume.
6 7 8 |
# File 'lib/evestatic/itemtypes.rb', line 6 def volume @volume end |
Class Method Details
.[](key = nil) ⇒ Object
INDEXED BY TYPE_ID! Static::ItemType.type_name => “Tritanium”
28 29 30 31 32 33 34 |
# File 'lib/evestatic/itemtypes.rb', line 28 def self.[](key=nil) unless key @@item_types_by_id else @@item_types_by_id[key] || self.new(key, 0, "UKNOWN TYPE (#{key})",0,0.0) end end |
.by_id(id = nil) ⇒ Object
36 37 38 |
# File 'lib/evestatic/itemtypes.rb', line 36 def self.by_id(id=nil) self.[](id) end |
.by_name(key = nil) ⇒ Object
INDEXED BY NAME! Static::ItemType.type_id => 34
41 42 43 44 45 46 47 48 49 |
# File 'lib/evestatic/itemtypes.rb', line 41 def self.by_name(key=nil) unless key @@item_types_by_name else res = @@item_types_by_name[key] raise NameError.new "Type not found #{key}" unless res res end end |
.load! ⇒ Object
11 12 13 |
# File 'lib/evestatic/itemtypes.rb', line 11 def self.load! ItemType.load_from_file(File.("../../../data/invTypes.csv", __FILE__)) end |
.load_from_file(path) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/evestatic/itemtypes.rb', line 15 def self.load_from_file(path) begin CSV.foreach(path, {col_sep: ";", headers: true}) do |row| @@item_types_by_id[row[0].to_i] = self.new(row[0].to_i, row[1].to_i, row[2], row[3].to_i, row[4].gsub(",",".").to_f) @@item_types_by_name[row[2]] = @@item_types_by_id[row[0].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 |