Class: ESM::Arma::ClassLookup

Inherits:
Object
  • Object
show all
Defined in:
lib/esm/model/arma/class_lookup.rb

Defined Under Namespace

Classes: Entry

Constant Summary collapse

CATEGORY_VEHICLES =
%w[
  vehicle_static
  vehicle_car
  vehicle_tank
  vehicle_boat
  vehicle_helicopter
  vehicle_plan
  vehicle_misc
].freeze
CATEGORY_EXILE =
%w[
  exile_medical
  exile_container
  exile_construction
  exile_consumables
  exile_misc
].freeze
CATEGORY_WEAPONS =
%w[
  handguns
  items
  launchers
  machine_guns
  melee
  misc_weapons
  rifles
  sniper_rifles
  sub_machine_guns
].freeze
CATEGORY_MAGAZINES =
%w[
  magazines_explosives
  magazines_grenades
  magazines_rockets
  magazines
].freeze
CATEGORY_CLOTHING =
%w[
  clothing_backpacks
  clothing_headgear
  clothing_uniforms
  clothing_vests
].freeze
CATEGORY_ATTACHMENTS =
%w[
  attachment_bipods
  attachment_sights
  attachments_muzzles
  attachments_pointers
].freeze

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.lookupObject (readonly) Also known as: all

Returns the value of attribute lookup.



60
61
62
# File 'lib/esm/model/arma/class_lookup.rb', line 60

def lookup
  @lookup
end

Class Method Details

.find(class_name) ⇒ Object



63
64
65
# File 'lib/esm/model/arma/class_lookup.rb', line 63

def find(class_name)
  @lookup[class_name.to_s]
end

.where(**query) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/esm/model/arma/class_lookup.rb', line 67

def where(**query)
  if !query.all? { |k, _v| Entry.members.include?(k.to_sym) }
    raise ESM::Exception::Error, "Invalid key or value is not a string"
  end

  @lookup.select do |class_name, entry|
    query.all? do |key, value|
      result = entry.send(key.to_sym)

      if value.is_a?(Array)
        value.any? { |v| result == v }
      else
        result == value
      end
    end
  end
end