Class: Gloomhaven::Perk

Inherits:
Object
  • Object
show all
Defined in:
lib/gloomhaven/perk.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ Perk

Returns a new instance of Perk.



5
6
7
8
9
10
11
12
13
# File 'lib/gloomhaven/perk.rb', line 5

def initialize(key)
  validate!(key)

  perk_hash = PERKS[key]
  @key = key
  @description = perk_hash['description']
  @adds = perk_hash['add'] || []
  @removes = perk_hash['remove'] || []
end

Instance Attribute Details

#addsObject (readonly)

Returns the value of attribute adds.



3
4
5
# File 'lib/gloomhaven/perk.rb', line 3

def adds
  @adds
end

#descriptionObject (readonly)

Returns the value of attribute description.



3
4
5
# File 'lib/gloomhaven/perk.rb', line 3

def description
  @description
end

#keyObject (readonly)

Returns the value of attribute key.



3
4
5
# File 'lib/gloomhaven/perk.rb', line 3

def key
  @key
end

#removesObject (readonly)

Returns the value of attribute removes.



3
4
5
# File 'lib/gloomhaven/perk.rb', line 3

def removes
  @removes
end

Instance Method Details

#cardsObject

returns a hash of card objects Ex: Perk.new.cards => { add: [Card, Card], remove: [Card, Card, Card] }



19
20
21
22
23
24
# File 'lib/gloomhaven/perk.rb', line 19

def cards
  result = { 'add' => [], 'remove' => [] }
  adds.each { |effect| result['add'] = 1.upto(effect['count']).map { Card.new(effect['card_name']) } }
  removes.each { |effect| result['remove'] = 1.upto(effect['count']).map { Card.new(effect['card_name']) } }
  result
end