Class: Nudge::CodeblockPoint

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(contents = []) ⇒ CodeblockPoint

Returns a new instance of CodeblockPoint.

Raises:

  • (ArgumentError)


43
44
45
46
# File 'lib/interpreter/programPoints.rb', line 43

def initialize(contents = [])
  raise(ArgumentError,"CodeblockPoint must be passed an Array") unless contents.kind_of?(Array)
  @contents = contents
end

Instance Attribute Details

#contentsObject

Returns the value of attribute contents.



41
42
43
# File 'lib/interpreter/programPoints.rb', line 41

def contents
  @contents
end

Instance Method Details

#blueprintObject



72
73
74
75
# File 'lib/interpreter/programPoints.rb', line 72

def blueprint
  t,b = blueprint_parts
  return "#{t} \n#{b}".strip
end

#blueprint_partsObject



64
65
66
67
68
69
70
# File 'lib/interpreter/programPoints.rb', line 64

def blueprint_parts
  fn = self.contents.inject("\n") do |fn_accumulator, branch|
    rhs = branch.blueprint_parts[1].empty? ? "" :  "\n#{branch.blueprint_parts[1]}"
    fn_accumulator + rhs
  end
  return [self.tidy, fn.strip]
end

#each {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



77
78
79
80
81
82
# File 'lib/interpreter/programPoints.rb', line 77

def each
  yield self
  @contents.each do |child|
    child.each {|c| yield c}
  end
end

#go(context) ⇒ Object



52
53
54
# File 'lib/interpreter/programPoints.rb', line 52

def go(context)
  @contents.reverse.each {|item| context.stacks[:exec].push(item)} 
end

#pointsObject



48
49
50
# File 'lib/interpreter/programPoints.rb', line 48

def points
  @contents.inject(1) {|count, daughter| count + daughter.points}
end

#tidy(level = 1) ⇒ Object



56
57
58
59
60
61
62
# File 'lib/interpreter/programPoints.rb', line 56

def tidy(level=1)
  tt = "block {"
  indent = level*2
  @contents.each {|item| tt += ("\n" + (" "*indent) + item.tidy(level+1))}
  tt += "}"
  return tt
end