class Smite::ItemEffect

Attributes

amount[RW]
attribute[RW]
device_name[R]
percentage[RW]

Public Class Methods

new(item, data = {}) click to toggle source
# File lib/smite/item_effect.rb, line 6
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

Public Instance Methods

inspect() click to toggle source
# File lib/smite/item_effect.rb, line 32
def inspect
  "#<Smite::ItemEffect '#{device_name}' #{attribute} +#{amount}#{percentage}>"
end
percentage?() click to toggle source
# File lib/smite/item_effect.rb, line 24
def percentage?
  !percentage.nil?
end
to_h() click to toggle source
# File lib/smite/item_effect.rb, line 28
def to_h
  { attribute => { amount: amount, percentage: percentage? } }
end