Sha256: 96f1e116570de592fe6e4254cee69469339cf2068b7c2bff10dc0776ee56e160

Contents?: true

Size: 963 Bytes

Versions: 1

Compression:

Stored size: 963 Bytes

Contents

class MWO::Weapon
  attr_accessor :weapon_id, :name, :type, :num_firing, :damage, :heatpenalty, :heat, :factions

  extend MWO::Utils

  def initialize args = {}
    args.each do |k,v|
      instance_variable_set("@#{k}", v) unless v.nil?
    end
  end

  def self.all(overrides: {})
    client = MWO::Client.new(overrides: {})
    raw = fetch(client.items_url)

    weapons = []

    raw.each do |weapon_id, attrs|
      if attrs["category"] == "weapon"


        weapon = {weapon_id: weapon_id.to_i,
                  name: attrs["name"],
                  category: attrs["category"],
                  stats: {}}

        if attrs["factions"]
          weapon[:factions] = {}
          attrs["factions"].each do |k,v|
            weapon[:factions][to_symbol(k)] = v
          end
        end

        attrs["stats"].each do |k,v|
          weapon[to_symbol(k)] = v
        end

        weapons << new(weapon)
      end

    end

    return weapons

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mwo-0.0.1 lib/mwo/weapon.rb