Class: Lotto::Draw

Inherits:
Object
  • Object
show all
Defined in:
lib/lotto/draw.rb

Instance Method Summary collapse

Instance Method Details

#basketObject



26
27
28
29
30
31
# File 'lib/lotto/draw.rb', line 26

def basket
  numbers = (1..@options[:of])
  numbers = numbers.reject{ |n| @options[:include].include? n } unless @options[:include].nil?
  numbers = numbers.reject{ |n| @options[:exclude].include? n } unless @options[:exclude].nil?
  numbers
end

#drawObject



8
9
10
11
12
13
14
# File 'lib/lotto/draw.rb', line 8

def draw
  drawns = []
  @options[:include].each{ |n| drawns << n } unless @options[:include].nil?
  count = @options[:include] ? @options[:pick] - @options[:include].count : @options[:pick]
  count.times{ drawns << pick(drawns) }
  drawns
end

#draw_multipleObject



16
17
18
19
20
# File 'lib/lotto/draw.rb', line 16

def draw_multiple
  coupons = []
  @options[:for].times{ coupons << draw }
  coupons
end

#pick(drawns = []) ⇒ Object



22
23
24
# File 'lib/lotto/draw.rb', line 22

def pick(drawns = [])
  basket.reject { |n| drawns.include? n }.sample
end

#play(options) ⇒ Object



3
4
5
6
# File 'lib/lotto/draw.rb', line 3

def play(options)
  @options = options
  @options[:for].nil? ? draw : draw_multiple
end