Module: StateMachines::STDIORenderer
- Defined in:
- lib/state_machines/stdio_renderer.rb
Class Method Summary collapse
- .draw_branch(branch, graph, event, options: {}, io: $stdout) ⇒ Object
- .draw_class(machine:, io: $stdout) ⇒ Object
- .draw_event(event, graph, options: {}, io: $stdout) ⇒ Object
- .draw_events(machine:, io: $stdout) ⇒ Object
- .draw_machine(machine, io: $stdout) ⇒ Object
- .draw_requirement(requirement) ⇒ Object
- .draw_state(state, graph, options: {}, io: $stdout) ⇒ Object
- .draw_states(machine:, io: $stdout) ⇒ Object
Class Method Details
.draw_branch(branch, graph, event, options: {}, io: $stdout) ⇒ Object
31 32 33 34 |
# File 'lib/state_machines/stdio_renderer.rb', line 31 module_function def draw_branch(branch, graph, event, options: {}, io: $stdout) io = io || [:io] || $stdout io.puts " Branch: #{branch.inspect}" end |
.draw_class(machine:, io: $stdout) ⇒ Object
11 12 13 |
# File 'lib/state_machines/stdio_renderer.rb', line 11 module_function def draw_class(machine:, io: $stdout) io.puts "Class: #{machine.owner_class.name}" end |
.draw_event(event, graph, options: {}, io: $stdout) ⇒ Object
26 27 28 29 |
# File 'lib/state_machines/stdio_renderer.rb', line 26 module_function def draw_event(event, graph, options: {}, io: $stdout) io = io || [:io] || $stdout io.puts " Event: #{event.name}" end |
.draw_events(machine:, io: $stdout) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/state_machines/stdio_renderer.rb', line 41 module_function def draw_events(machine:, io: $stdout) io.puts " Events:" if machine.events.to_a.empty? io.puts " - None" else machine.events.each do |event| io.puts " - #{event.name}" event.branches.each do |branch| branch.state_requirements.each do |requirement| out = +" - " out << "#{draw_requirement(requirement[:from])} => #{draw_requirement(requirement[:to])}" out << " IF #{branch.if_condition}" if branch.if_condition out << " UNLESS #{branch.unless_condition}" if branch.unless_condition io.puts out end end end end end |
.draw_machine(machine, io: $stdout) ⇒ Object
5 6 7 8 9 |
# File 'lib/state_machines/stdio_renderer.rb', line 5 module_function def draw_machine(machine, io: $stdout) draw_class(machine: machine, io: io) draw_states(machine: machine, io: io) draw_events(machine: machine, io: io) end |
.draw_requirement(requirement) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/state_machines/stdio_renderer.rb', line 61 module_function def draw_requirement(requirement) case requirement when StateMachines::BlacklistMatcher "ALL EXCEPT #{requirement.values.join(', ')}" when StateMachines::AllMatcher "ALL" when StateMachines::LoopbackMatcher "SAME" else requirement.values.join(', ') end end |
.draw_state(state, graph, options: {}, io: $stdout) ⇒ Object
36 37 38 39 |
# File 'lib/state_machines/stdio_renderer.rb', line 36 module_function def draw_state(state, graph, options: {}, io: $stdout) io = io || [:io] || $stdout io.puts " State: #{state.name}" end |
.draw_states(machine:, io: $stdout) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/state_machines/stdio_renderer.rb', line 15 module_function def draw_states(machine:, io: $stdout) io.puts " States:" if machine.states.to_a.empty? io.puts " - None" else machine.states.each do |state| io.puts " - #{state.name}" end end end |