Class: Lotto::Draw
- Inherits:
-
Object
- Object
- Lotto::Draw
- Defined in:
- lib/lotto/draw.rb
Instance Method Summary collapse
- #basket ⇒ Object
- #draw ⇒ Object
- #draw_multiple ⇒ Object
- #pick(drawns = []) ⇒ Object
- #play(options) ⇒ Object
Instance Method Details
#basket ⇒ Object
26 27 28 29 30 31 |
# File 'lib/lotto/draw.rb', line 26 def basket numbers = (1..[:of]) numbers = numbers.reject{ |n| [:include].include? n } unless [:include].nil? numbers = numbers.reject{ |n| [:exclude].include? n } unless [:exclude].nil? numbers end |
#draw ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/lotto/draw.rb', line 8 def draw drawns = [] [:include].each{ |n| drawns << n } unless [:include].nil? count = [:include] ? [:pick] - [:include].count : [:pick] count.times{ drawns << pick(drawns) } drawns end |
#draw_multiple ⇒ Object
16 17 18 19 20 |
# File 'lib/lotto/draw.rb', line 16 def draw_multiple coupons = [] [: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() = [:for].nil? ? draw : draw_multiple end |