Sha256: 2c8dc894574626ee2c329d1fff000284a1fa8bd10e154b139a2f0915805147fe

Contents?: true

Size: 881 Bytes

Versions: 2

Compression:

Stored size: 881 Bytes

Contents

module Smite
  class ItemEffect
    attr_accessor :attribute, :amount, :percentage
    attr_reader :device_name

    def initialize(item, data = {})
      @device_name = item
      return if data.empty?

      effect = data.delete('Description').tr(' ','')
      effect = ActiveSupport::Inflector.underscore(effect)

      @attribute = effect
      @attribute = 'magic_protection' if effect == 'magical_protection'
      @attribute = 'magical_power'    if effect == 'magic_power'

      value       = data.delete('Value')
      @percentage = value[/%/]

      value   = value.tr('+', '').to_f
      @amount = value
    end

    def percentage?
      !percentage.nil?
    end

    def to_h
      { attribute => { amount: amount, percentage: percentage? } }
    end

    def inspect
      "#<Smite::ItemEffect '#{device_name}' #{attribute} +#{amount}#{percentage}>"
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
smite_ruby-1.5.1 lib/smite/item_effect.rb
smite_ruby-1.5.0 lib/smite/item_effect.rb