Class: FormatText::Context
- Inherits:
-
Object
- Object
- FormatText::Context
- Defined in:
- lib/fto.rb
Overview
Each time an effector’s pattern is matched, its code attribute is called with this structure, which is used to communicate details to the code block, and by the code block to pass back some behaviour modification notes. Most of the attributes should be treated as read-only, with exceptions noted below in the attribute descriptions.
This class is used internally by the fto library and isn’t really intended for external consumption.
Instance Attribute Summary collapse
-
#argList ⇒ Object
Array.
-
#effectorObj ⇒ Object
FormatText::Effector object.
-
#ftoObj ⇒ Object
FTO object.
-
#lastArgUsed ⇒ Object
Any.
-
#reuseArg ⇒ Object
Boolean.
-
#sMatched ⇒ Object
String.
-
#usedArgs ⇒ Object
Array.
Instance Method Summary collapse
-
#initialize(*argsp) ⇒ Context
constructor
Create a new FormatText::Context object.
Constructor Details
#initialize(*argsp) ⇒ Context
Create a new FormatText::Context object. There may only be a single argument to the constructor, and it must be a hash, using symbols for the names of the attributes to set:
x = FormatText::Context.new({ :sMatched => 'string', :reuseArg => false })
This class is used internally by the fto library and isn’t really intended for external consumption.
:call-seq:
new<i>(Hash)</i> => <i>FormatText::Context object</i>
186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/fto.rb', line 186 def initialize(*argsp) (@effectorObj, @ftoObj) = nil @sMatched = '' @usedArgs = [] @argList = [] @reuseArg = false if (argsp[0].class != Hash) raise RuntimeError, self.class.name + _(' requires a Hash to create') end argsp[0].each { |key,val| eval("self.#{key.to_s} = val") } end |
Instance Attribute Details
#argList ⇒ Object
Array. List of arguments already processed. Usually read-only. The effector function is responsible for using the values in this array to perform its task.
The only time this should be considered read/write is when the effector is intended to modify the list of arguments being used to build the final string. The argList attribute should be modified in conjunction with usedArgs to maintain continuity. By default, after the effector function returns, the caller (the FTO#format() method) will take the element from the front of the argList array and push it onto the end of the usedArgs array.
157 158 159 |
# File 'lib/fto.rb', line 157 def argList @argList end |
#effectorObj ⇒ Object
FormatText::Effector object. The Effector object involved. Read-only.
122 123 124 |
# File 'lib/fto.rb', line 122 def effectorObj @effectorObj end |
#ftoObj ⇒ Object
FTO object. The FTO object being processed. Read-only.
128 129 130 |
# File 'lib/fto.rb', line 128 def ftoObj @ftoObj end |
#lastArgUsed ⇒ Object
Any. The FTO#format() sets this to the last argument that was actually used.
163 164 165 |
# File 'lib/fto.rb', line 163 def lastArgUsed @lastArgUsed end |
#reuseArg ⇒ Object
Boolean. The effector function sets this to true to inhibit the FTO#format() method from modifying the argument list after the function returns. See the descriptions under the argList and usedArgs attributes.
171 172 173 |
# File 'lib/fto.rb', line 171 def reuseArg @reuseArg end |
#sMatched ⇒ Object
String. The string that matched the effector and triggered its processing. Read-only.
134 135 136 |
# File 'lib/fto.rb', line 134 def sMatched @sMatched end |
#usedArgs ⇒ Object
Array. Arguments remaining to be processed. Usually read-only, but see the description of the usedArgs attribute for exceptions.
141 142 143 |
# File 'lib/fto.rb', line 141 def usedArgs @usedArgs end |