Class: Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/ntm/configuration.rb

Overview

require “tape”

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Configuration



6
7
8
9
10
11
# File 'lib/ntm/configuration.rb', line 6

def initialize(options = {})
  @tape   = options[:tape] || Tape.new
  @state  = options[:state].to_i
  @depth = options[:depth].to_i || 1
  @path = []
end

Instance Attribute Details

#depthObject

Returns the value of attribute depth.



4
5
6
# File 'lib/ntm/configuration.rb', line 4

def depth
  @depth
end

#pathObject

Returns the value of attribute path.



4
5
6
# File 'lib/ntm/configuration.rb', line 4

def path
  @path
end

#stateObject

Returns the value of attribute state.



4
5
6
# File 'lib/ntm/configuration.rb', line 4

def state
  @state
end

#tapeObject

Returns the value of attribute tape.



4
5
6
# File 'lib/ntm/configuration.rb', line 4

def tape
  @tape
end

Instance Method Details

#dupObject



18
19
20
21
22
23
24
25
# File 'lib/ntm/configuration.rb', line 18

def dup
  conf = Configuration.new
  conf.state = @state
  conf.tape = @tape.dup
  conf.depth = @depth
  conf.path = @path.dup
  conf
end

#to_sObject



13
14
15
16
# File 'lib/ntm/configuration.rb', line 13

def to_s
  conf = @tape.instance_variable_get(:@content).dup
  conf.insert(@tape.head_position, "[q#{@state}]").collect!{|e| e ? e : Tape::BLANK }.join
end