Class: Blirb::Coordinator

Inherits:
Object show all
Defined in:
lib/blirb/coordinator.rb

Constant Summary collapse

DEFAULT_TASKS =
File.expand_path('../../../blirb_tasks/tasks.rb', __FILE__)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path = nil) ⇒ Coordinator

Returns a new instance of Coordinator.



6
7
8
9
10
11
12
13
14
# File 'lib/blirb/coordinator.rb', line 6

def initialize file_path = nil
  @tasks = []
  load_tasks file_path  || DEFAULT_TASKS
  @current_task = nil
  blirb = self
  Object.class_eval do
    @blirb = blirb
  end
end

Instance Attribute Details

#current_taskObject (readonly)

Returns the value of attribute current_task.



3
4
5
# File 'lib/blirb/coordinator.rb', line 3

def current_task
  @current_task
end

#tasksObject (readonly)

Returns the value of attribute tasks.



3
4
5
# File 'lib/blirb/coordinator.rb', line 3

def tasks
  @tasks
end

Instance Method Details

#goObject



16
17
18
19
# File 'lib/blirb/coordinator.rb', line 16

def go
  menu
  IRB.start
end

displays menu, sets the current task



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/blirb/coordinator.rb', line 22

def menu
  end_tutorial if remaining_tasks.empty?
  list_commands
  puts "\nPlease choose a task by entering task number (completed tasks will not appear):\n\n"
  list_tasks

  while true
    print "\n> "
    if integer?( (selection = gets.chomp) ) && @tasks[(selection = selection.to_i)]
      select_task selection
      break
    elsif selection == 'q' || selection == 'exit' # variety is the spice of life
      exit
    end
    puts "Sorry, I'm not sure what you're trying to do. Please do something different."
  end
end