Class: Nudge::ValuePoint
Defined Under Namespace
Classes: UnassignedValuePointError
Instance Attribute Summary collapse
Instance Method Summary
collapse
#each
Constructor Details
#initialize(type, representation = nil) ⇒ ValuePoint
Returns a new instance of ValuePoint.
92
93
94
95
96
|
# File 'lib/interpreter/programPoints.rb', line 92
def initialize(type,representation=nil)
raise(ArgumentError, "Type must be a symbol or string") unless [Symbol,String].include?(type.class)
@type = type.to_sym
@raw = representation.nil? ? nil : representation.to_s
end
|
Instance Attribute Details
#raw ⇒ Object
Returns the value of attribute raw.
89
90
91
|
# File 'lib/interpreter/programPoints.rb', line 89
def raw
@raw
end
|
#type ⇒ Object
Returns the value of attribute type.
89
90
91
|
# File 'lib/interpreter/programPoints.rb', line 89
def type
@type
end
|
#value ⇒ Object
Returns the value of attribute value.
90
91
92
|
# File 'lib/interpreter/programPoints.rb', line 90
def value
@value
end
|
Instance Method Details
#blueprint ⇒ Object
151
152
153
154
|
# File 'lib/interpreter/programPoints.rb', line 151
def blueprint
pts = self.blueprint_parts
return "#{pts[0]} \n#{pts[1]}"
end
|
#blueprint_parts ⇒ Object
146
147
148
149
|
# File 'lib/interpreter/programPoints.rb', line 146
def blueprint_parts
fn = "«#{self.type}» #{self.raw}".strip
return [self.tidy, fn]
end
|
#clone ⇒ Object
111
112
113
|
# File 'lib/interpreter/programPoints.rb', line 111
def clone
ValuePoint.new(@type, @raw.dup)
end
|
#go(context) ⇒ Object
98
99
100
101
102
103
104
|
# File 'lib/interpreter/programPoints.rb', line 98
def go(context)
raise(UnassignedValuePointError, "#{self.type} point has no value string") if self.value == nil
context.stacks[self.type].push(self)
rescue UnassignedValuePointError => exc
msg = ValuePoint.new("error", exc.message)
context.stacks[:error].push msg
end
|
#nudgetype(typename = @type) ⇒ Object
120
121
122
|
# File 'lib/interpreter/programPoints.rb', line 120
def nudgetype(typename=@type)
"#{typename.to_s.camelize}Type"
end
|
#nudgetype_defined?(typename = @type) ⇒ Boolean
124
125
126
|
# File 'lib/interpreter/programPoints.rb', line 124
def nudgetype_defined?(typename=@type)
Nudge.const_defined?(nudgetype(typename).to_sym)
end
|
#points ⇒ Object
116
117
118
|
# File 'lib/interpreter/programPoints.rb', line 116
def points
1
end
|
#randomize(context) ⇒ Object
140
141
142
143
144
|
# File 'lib/interpreter/programPoints.rb', line 140
def randomize(context)
newType = context.types.sample
@type = newType.to_nudgecode
@raw = newType.any_value
end
|
#tidy(level = 1) ⇒ Object
136
137
138
|
# File 'lib/interpreter/programPoints.rb', line 136
def tidy(level=1)
"value «" + @type.to_s + "»"
end
|