Class: Smite::ItemEffect

Inherits:
Object
  • Object
show all
Defined in:
lib/smite/item_effect.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(item, data = {}) ⇒ ItemEffect

Returns a new instance of ItemEffect.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 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

Instance Attribute Details

#amountObject

Returns the value of attribute amount.



3
4
5
# File 'lib/smite/item_effect.rb', line 3

def amount
  @amount
end

#attributeObject

Returns the value of attribute attribute.



3
4
5
# File 'lib/smite/item_effect.rb', line 3

def attribute
  @attribute
end

#device_nameObject (readonly)

Returns the value of attribute device_name.



4
5
6
# File 'lib/smite/item_effect.rb', line 4

def device_name
  @device_name
end

#percentageObject

Returns the value of attribute percentage.



3
4
5
# File 'lib/smite/item_effect.rb', line 3

def percentage
  @percentage
end

Instance Method Details

#inspectObject



32
33
34
# File 'lib/smite/item_effect.rb', line 32

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

#percentage?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/smite/item_effect.rb', line 24

def percentage?
  !percentage.nil?
end

#to_hObject



28
29
30
# File 'lib/smite/item_effect.rb', line 28

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