Class: Encounter

Inherits:
Object show all
Defined in:
lib/encounters/encounter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(monster, amount, id = nil, xp_value = nil) ⇒ Encounter

Returns a new instance of Encounter.



5
6
7
8
9
10
# File 'lib/encounters/encounter.rb', line 5

def initialize( monster, amount, id = nil, xp_value = nil )
  @monster = monster
  @amount = amount
  @xp_value = xp_value ? xp_value : encounter_xp_value.to_i
  @id = id ? id : ( monster.key.to_s + '_' + amount.to_s ).to_sym
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/encounters/encounter.rb', line 3

def id
  @id
end

#xp_valueObject (readonly)

Returns the value of attribute xp_value.



3
4
5
# File 'lib/encounters/encounter.rb', line 3

def xp_value
  @xp_value
end

Instance Method Details

#to_hashObject



16
17
18
# File 'lib/encounters/encounter.rb', line 16

def to_hash
  { id: @id, monster_key: @monster.key, amount: @amount, xp_value: @xp_value }
end

#to_sObject



12
13
14
# File 'lib/encounters/encounter.rb', line 12

def to_s
  "#{@amount} #{@monster.name}"
end