Class: Gacha::Box

Inherits:
Object
  • Object
show all
Defined in:
lib/gacha/box.rb

Instance Method Summary collapse

Constructor Details

#initializeBox

Returns a new instance of Box.



3
4
5
6
# File 'lib/gacha/box.rb', line 3

def initialize()
  self.clear
  @consumable = false
end

Instance Method Details

#add(item) ⇒ Object



22
23
24
25
# File 'lib/gacha/box.rb', line 22

def add(item)
  @items.push(item)
  @total_rate += item.rate
end

#clearObject



38
39
40
41
# File 'lib/gacha/box.rb', line 38

def clear
  @items = []
  @total_rate = 0
end

#consumable?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/gacha/box.rb', line 55

def consumable?
  @consumable
end

#countObject



47
48
49
# File 'lib/gacha/box.rb', line 47

def count
  @items.count
end

#drawObject



12
13
14
15
16
17
18
19
20
# File 'lib/gacha/box.rb', line 12

def draw
  position = self.random_position
  return nil if position == nil
  item = self.find(position)
  if item != nil and @consumable
    self.remove(item)
  end
  return item
end

#empty?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/gacha/box.rb', line 43

def empty?
  @items.empty? and @total_rate == 0
end

#remove(item) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/gacha/box.rb', line 27

def remove(item)
  @items.delete_if do |x|
    if x == item
      @total_rate -= item.rate
      true
    else
      false
    end
  end
end

#set_consumable(consumable) ⇒ Object



51
52
53
# File 'lib/gacha/box.rb', line 51

def set_consumable(consumable)
  @consumable = consumable
end

#to_sObject



8
9
10
# File 'lib/gacha/box.rb', line 8

def to_s
  "Gacha::Box #{@items.join(", ")}"
end