Class: Command::PlaybackInterpreter

Inherits:
TextInterpreter show all
Defined in:
lib/command-set/interpreter/recording.rb

Instance Attribute Summary

Attributes inherited from TextInterpreter

#complete_line

Attributes inherited from BaseInterpreter

#command_set, #logger, #out_io, #sub_modes, #subject

Instance Method Summary collapse

Methods inherited from TextInterpreter

#complete, #cook_input, #get_formatters, #get_prompt, #output_exception, #pause_before_dying, #prompt_user, #readline_complete, #split_line, #stop

Methods inherited from BaseInterpreter

#behavior, #fill_subject, #get_formatter, #get_formatters, #get_subject, #next_command, #pop_mode, #prep_subject, #process_input, #prompt_user, #push_mode, #subject_requirements

Constructor Details

#initialize(recording, pause_for) ⇒ PlaybackInterpreter

Returns a new instance of PlaybackInterpreter.



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/command-set/interpreter/recording.rb', line 102

def initialize(recording, pause_for)
  setup = nil
  File::open(recording) do |record|
    setup = YAML::load(record)
  end
 
  @events = setup['events']
  module_name = setup['module_name']
  command_set_path = setup['set_path']

  super()
  self.command_set = CommandSet::define_commands do
    require_commands(module_name, command_set_path)
  end

  @pause_for = pause_for
end

Instance Method Details

#goObject



120
121
122
123
124
125
126
# File 'lib/command-set/interpreter/recording.rb', line 120

def go
  ([nil] + @events).each_cons(2) do |last, event|
    sleep(@pause_for) unless @pause_for.nil?
    event.playback(get_prompt, self, last)
    $stdout.flush
  end
end