Class: Evestatic::ItemType

Inherits:
Object
  • Object
show all
Defined in:
lib/evestatic/itemtypes.rb

Constant Summary collapse

@@item_types_by_id =
{}
@@item_types_by_name =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_idObject

Returns the value of attribute group_id.



6
7
8
# File 'lib/evestatic/itemtypes.rb', line 6

def group_id
  @group_id
end

#massObject

Returns the value of attribute mass.



6
7
8
# File 'lib/evestatic/itemtypes.rb', line 6

def mass
  @mass
end

#type_idObject

Returns the value of attribute type_id.



6
7
8
# File 'lib/evestatic/itemtypes.rb', line 6

def type_id
  @type_id
end

#type_nameObject

Returns the value of attribute type_name.



6
7
8
# File 'lib/evestatic/itemtypes.rb', line 6

def type_name
  @type_name
end

#volumeObject

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.expand_path("../../../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