Class: Nudge::InstructionPoint

Inherits:
ProgramPoint show all
Defined in:
lib/interpreter/programPoints.rb

Defined Under Namespace

Classes: InstructionNotFoundError

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ProgramPoint

#each

Constructor Details

#initialize(name) ⇒ InstructionPoint

Returns a new instance of InstructionPoint.



206
207
208
# File 'lib/interpreter/programPoints.rb', line 206

def initialize(name)
  @name = name
end

Instance Attribute Details

#effectsObject

Returns the value of attribute effects.



205
206
207
# File 'lib/interpreter/programPoints.rb', line 205

def effects
  @effects
end

#nameObject

Returns the value of attribute name.



205
206
207
# File 'lib/interpreter/programPoints.rb', line 205

def name
  @name
end

#requirementsObject

Returns the value of attribute requirements.



205
206
207
# File 'lib/interpreter/programPoints.rb', line 205

def requirements
  @requirements
end

Instance Method Details

#blueprintObject



248
249
250
# File 'lib/interpreter/programPoints.rb', line 248

def blueprint
  return self.tidy
end

#blueprint_partsObject



244
245
246
# File 'lib/interpreter/programPoints.rb', line 244

def blueprint_parts
  [self.tidy,""]
end

#classLookupObject



214
215
216
217
218
# File 'lib/interpreter/programPoints.rb', line 214

def classLookup
  self.className.constantize
rescue NameError
  raise InstructionNotFoundError, "#{self.className} is not an active instruction in this context"
end

#classNameObject



210
211
212
# File 'lib/interpreter/programPoints.rb', line 210

def className
  "#{@name.camelize}Instruction"
end

#go(context) ⇒ Object



231
232
233
234
235
236
237
# File 'lib/interpreter/programPoints.rb', line 231

def go(context)
  className = self.classLookup
  context.instructions_library[className].go
rescue InstructionNotFoundError => exc
  msg = ValuePoint.new("error", exc.message)
  context.stacks[:error].push msg
end

#pointsObject



224
225
226
# File 'lib/interpreter/programPoints.rb', line 224

def points
  1
end

#randomize(context) ⇒ Object



239
240
241
242
# File 'lib/interpreter/programPoints.rb', line 239

def randomize(context)
  instructionName = context.instructions.sample.to_s
  @name = instructionName.slice(0..-12).underscore
end

#tidy(level = 1) ⇒ Object



220
221
222
# File 'lib/interpreter/programPoints.rb', line 220

def tidy(level=1)
  "do " + @name
end