Class: Nudge::CliRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/cli/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, options = {}) ⇒ CliRunner

Returns a new instance of CliRunner.



13
14
15
16
17
18
# File 'lib/cli/runner.rb', line 13

def initialize(filename, options={})
  @filename = filename
  @nudge_program = NudgeProgram.new("")
  @options = options
  @interpreter = Interpreter.new("",@options)
end

Instance Attribute Details

#filenameObject

Returns the value of attribute filename.



5
6
7
# File 'lib/cli/runner.rb', line 5

def filename
  @filename
end

#interpreterObject

Returns the value of attribute interpreter.



8
9
10
# File 'lib/cli/runner.rb', line 8

def interpreter
  @interpreter
end

#nudge_programObject

Returns the value of attribute nudge_program.



7
8
9
# File 'lib/cli/runner.rb', line 7

def nudge_program
  @nudge_program
end

#optionsObject

Returns the value of attribute options.



9
10
11
# File 'lib/cli/runner.rb', line 9

def options
  @options
end

#raw_codeObject

Returns the value of attribute raw_code.



6
7
8
# File 'lib/cli/runner.rb', line 6

def raw_code
  @raw_code
end

#resultObject

Returns the value of attribute result.



10
11
12
# File 'lib/cli/runner.rb', line 10

def result
  @result
end

Instance Method Details

#runObject



29
30
31
# File 'lib/cli/runner.rb', line 29

def run
  return @interpreter.run
end

#setup(options = {}) ⇒ Object



21
22
23
24
25
26
# File 'lib/cli/runner.rb', line 21

def setup(options = {})
  @raw_code = IO.open(@filename)
  @interpreter.reset(@raw_code)
  options[:variables].each {|name, val| @interpreter.bind_variable(name, val)} if options[:variables]
  options[:sensors].each {|name, block| @interpreter.register_sensor(name, &block)} if options[:sensors]
end