Class: Mel::SceneFSM

Inherits:
Object
  • Object
show all
Defined in:
lib/mel/scene-fsm.rb

Instance Method Summary collapse

Instance Method Details

#actionObject

all states should override this method



46
# File 'lib/mel/scene-fsm.rb', line 46

def action = false

#ask_prompt(choices) ⇒ Object



22
23
24
# File 'lib/mel/scene-fsm.rb', line 22

def ask_prompt(choices)
  prompt.select("Choose your Path", choices, per_page: choices_per_page)
end

#blank_spaceObject



18
19
20
# File 'lib/mel/scene-fsm.rb', line 18

def blank_space
  puts ""
end

#choicesObject

all states should override this method



38
39
40
# File 'lib/mel/scene-fsm.rb', line 38

def choices
  []
end

#choices_per_pageObject



26
27
28
# File 'lib/mel/scene-fsm.rb', line 26

def choices_per_page
  20
end

#choose_destinationObject

display, choices, and action methods all change per-state



54
55
56
57
58
59
60
61
62
63
# File 'lib/mel/scene-fsm.rb', line 54

def choose_destination
  if (some_choices = choices)
    blank_space
    display
    blank_space
    ask_prompt(some_choices)
  else
    action
  end
end

#decobox(*lines) ⇒ Object



65
66
67
68
69
70
71
72
73
74
# File 'lib/mel/scene-fsm.rb', line 65

def decobox(*lines)
  lines = lines[0].split("\n") if lines.length == 1
  max_length = lines.map(&:length).max
  puts "+-#{"-" * max_length}-+"
  lines.each do |line|
    num_spacers = max_length - line.length
    puts "| #{line}#{" " * num_spacers} |"
  end
  puts "+-#{"-" * max_length}-+"
end

#displayObject

all states should override this method



43
# File 'lib/mel/scene-fsm.rb', line 43

def display = false

#promptObject



10
11
12
# File 'lib/mel/scene-fsm.rb', line 10

def prompt
  @prompt ||= TTY::Prompt.new
end

#spacerObject



14
15
16
# File 'lib/mel/scene-fsm.rb', line 14

def spacer
  puts "|+--------------------------------------------------------+|"
end

#still_running?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/mel/scene-fsm.rb', line 48

def still_running?
  true
end

#visit_submachine(machine) ⇒ Object

runs a machine until completion, signaled by still_running? returning false



31
32
33
34
35
# File 'lib/mel/scene-fsm.rb', line 31

def visit_submachine(machine)
  while machine.still_running?
    machine.choose_destination
  end
end