Class: Drills

Inherits:
Object
  • Object
show all
Includes:
Commands
Defined in:
lib/ruby_drills/drills.rb

Direct Known Subclasses

ArrayDrills, HashDrills, StringDrills

Constant Summary

Constants included from Commands

Commands::GAMBLER

Instance Method Summary collapse

Methods included from Commands

#back, #clear, #continue, #fail, #fold, #help, #hint, #quit, #review, #skip, #welcome, #win

Instance Method Details

#drillsObject

Determines the list of drills in this directory



43
44
45
46
47
48
49
50
51
# File 'lib/ruby_drills/drills.rb', line 43

def drills
  mod = self.class.name.gsub(/Drills/, '').downcase
  Dir["#{File.dirname(__FILE__)}/#{mod}/*drill.rb"].map do |f|
    require f
    name = File.basename(f, '.rb')
    clazz = name.split('_').map(&:capitalize).join
    Module.const_get(clazz).new
  end
end

#linked_drillsObject

Creates a linked list from the array of drills



28
29
30
31
32
33
34
35
# File 'lib/ruby_drills/drills.rb', line 28

def linked_drills
  ordered_drills.tap do |linked|
    for i in 0..linked.size-1
      linked[i].previous = linked[i-1] unless (i == 0)
      linked[i].next = linked[i+1] unless (i == linked.size-1)
    end
  end
end

#ordered_drillsObject

deliver drills in random order



38
39
40
# File 'lib/ruby_drills/drills.rb', line 38

def ordered_drills
  drills.shuffle
end

#startObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/ruby_drills/drills.rb', line 4

def start
  drill = linked_drills[0]
  while drill do
    drill.show

    begin
      input = Readline.readline("\n>> ", true)
    end while (!drill.done?(input))

    case input
    when 'back'
      drill = drill.previous
      clear
    when 'menu'
      break
    else
      drill = drill.next
      continue
    end

  end
end