Class: SGK::Gacha::MultipleDraw

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

Overview

10連ガチャ

使用例:

engine = SGK::Gacha::Engine.new(GachaCard.all)
drawer = SGK::Gacha::MultipleDraw.new(engine, draw_count: 10)
results = drawer.execute

Constant Summary collapse

DEFAULT_DRAW_COUNT =
10

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(engine, draw_count: DEFAULT_DRAW_COUNT) ⇒ MultipleDraw

初期化

Parameters:

  • engine (SGK::Gacha::Engine)

    使用するガチャエンジン

  • draw_count (Integer) (defaults to: DEFAULT_DRAW_COUNT)

    抽選するカードの枚数(デフォルト: 10)

Raises:

  • (ArgumentError)

    engineが無効、またはdraw_countが正の値でない場合



21
22
23
24
25
26
27
# File 'lib/sgk/gacha/multiple_draw.rb', line 21

def initialize(engine, draw_count: DEFAULT_DRAW_COUNT)
  raise ArgumentError, "Engine must be a SGK::Gacha::Engine instance" unless engine.is_a?(Engine)
  raise ArgumentError, "Draw count must be positive" unless draw_count.positive?

  @engine = engine
  @draw_count = draw_count
end

Instance Attribute Details

#draw_countObject (readonly)

Returns the value of attribute draw_count.



14
15
16
# File 'lib/sgk/gacha/multiple_draw.rb', line 14

def draw_count
  @draw_count
end

#engineObject (readonly)

Returns the value of attribute engine.



14
15
16
# File 'lib/sgk/gacha/multiple_draw.rb', line 14

def engine
  @engine
end

Instance Method Details

#executeArray<Object> Also known as: draw

複数抽選を実行する

Returns:

  • (Array<Object>)

    抽選されたカードの配列



32
33
34
# File 'lib/sgk/gacha/multiple_draw.rb', line 32

def execute
  @engine.draw_multiple(@draw_count)
end