Class: CoopAl::Loot

Inherits:
Object
  • Object
show all
Defined in:
lib/coop_al/loot.rb

Overview

Loot

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(treasures, items) ⇒ Loot

Returns a new instance of Loot.



8
9
10
11
# File 'lib/coop_al/loot.rb', line 8

def initialize(treasures, items)
  @treasures = treasures
  @items = items
end

Instance Attribute Details

#itemsObject (readonly)

Returns the value of attribute items.



6
7
8
# File 'lib/coop_al/loot.rb', line 6

def items
  @items
end

#treasuresObject (readonly)

Returns the value of attribute treasures.



6
7
8
# File 'lib/coop_al/loot.rb', line 6

def treasures
  @treasures
end

Class Method Details

.emptyObject



37
38
39
# File 'lib/coop_al/loot.rb', line 37

def self.empty
  Loot.new([], [])
end

.from_item(item) ⇒ Object



45
46
47
# File 'lib/coop_al/loot.rb', line 45

def self.from_item(item)
  Loot.new([], [item])
end

.from_treasure(treasure) ⇒ Object



41
42
43
# File 'lib/coop_al/loot.rb', line 41

def self.from_treasure(treasure)
  Loot.new([treasure], [])
end

Instance Method Details

#+(other) ⇒ Object



27
28
29
30
31
# File 'lib/coop_al/loot.rb', line 27

def +(other)
  @treasures += other.treasures
  @items += other.items
  self
end

#add_item(item) ⇒ Object



23
24
25
# File 'lib/coop_al/loot.rb', line 23

def add_item(item)
  @items << item
end

#add_treasure(treasure) ⇒ Object



19
20
21
# File 'lib/coop_al/loot.rb', line 19

def add_treasure(treasure)
  @treasures << treasure
end

#empty?Boolean

Returns:

  • (Boolean)


13
14
15
16
17
# File 'lib/coop_al/loot.rb', line 13

def empty?
  return false unless @treasures.empty?
  return false unless @items.empty?
  true
end

#treasure_valueObject



33
34
35
# File 'lib/coop_al/loot.rb', line 33

def treasure_value
  @treasures.inject(Value.new) { |a, e| a + e.value }
end