Class: Gacha::Box
- Inherits:
-
Object
- Object
- Gacha::Box
- Defined in:
- lib/gacha/box.rb
Instance Method Summary collapse
- #add(item) ⇒ Object
- #clear ⇒ Object
- #consumable? ⇒ Boolean
- #count ⇒ Object
- #draw ⇒ Object
- #empty? ⇒ Boolean
-
#initialize ⇒ Box
constructor
A new instance of Box.
- #remove(item) ⇒ Object
- #set_consumable(consumable) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Box
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 |
#clear ⇒ Object
38 39 40 41 |
# File 'lib/gacha/box.rb', line 38 def clear @items = [] @total_rate = 0 end |
#consumable? ⇒ Boolean
55 56 57 |
# File 'lib/gacha/box.rb', line 55 def consumable? @consumable end |
#count ⇒ Object
47 48 49 |
# File 'lib/gacha/box.rb', line 47 def count @items.count end |
#draw ⇒ Object
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
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_s ⇒ Object
8 9 10 |
# File 'lib/gacha/box.rb', line 8 def to_s "Gacha::Box #{@items.join(", ")}" end |