Class: Mel::SceneFSM
- Inherits:
-
Object
- Object
- Mel::SceneFSM
- Defined in:
- lib/mel/scene-fsm.rb
Instance Method Summary collapse
-
#action ⇒ Object
all states should override this method.
- #ask_prompt(choices) ⇒ Object
- #blank_space ⇒ Object
-
#choices ⇒ Object
all states should override this method.
- #choices_per_page ⇒ Object
-
#choose_destination ⇒ Object
display, choices, and action methods all change per-state.
- #decobox(*lines) ⇒ Object
-
#display ⇒ Object
all states should override this method.
- #prompt ⇒ Object
- #spacer ⇒ Object
- #still_running? ⇒ Boolean
-
#visit_submachine(machine) ⇒ Object
runs a machine until completion, signaled by still_running? returning false.
Instance Method Details
#action ⇒ Object
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_space ⇒ Object
18 19 20 |
# File 'lib/mel/scene-fsm.rb', line 18 def blank_space puts "" end |
#choices ⇒ Object
all states should override this method
38 39 40 |
# File 'lib/mel/scene-fsm.rb', line 38 def choices [] end |
#choices_per_page ⇒ Object
26 27 28 |
# File 'lib/mel/scene-fsm.rb', line 26 def choices_per_page 20 end |
#choose_destination ⇒ Object
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 |
#display ⇒ Object
all states should override this method
43 |
# File 'lib/mel/scene-fsm.rb', line 43 def display = false |
#prompt ⇒ Object
10 11 12 |
# File 'lib/mel/scene-fsm.rb', line 10 def prompt @prompt ||= TTY::Prompt.new end |
#spacer ⇒ Object
14 15 16 |
# File 'lib/mel/scene-fsm.rb', line 14 def spacer puts "|+--------------------------------------------------------+|" end |
#still_running? ⇒ 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 |