Class: MadderLib::AnytimePhrase
- Includes:
- Conditional::Recur::Phrase
- Defined in:
- lib/madderlib/phrase.rb
Overview
AnytimePhrase
A Phrase constructed by Builder#anywhere
Beyond what a standard Phrase can do, an AnytimePhrase can specify:
-
the range of positions where it can be inserted into the Builder result
-
recurring usage, via Conditional::Recur .\
This is not the same as having a repeating Instruction. \ The Phrase recurrance indicates how many times it is resolved and inserted into the Builder result. \ For example, a recurring Phrase can contain a repeating Instruction.
Instance Attribute Summary
Attributes inherited from Phrase
Instance Method Summary collapse
-
#after(ref = nil) ⇒ Object
States that this Phrase should only appear before the referenced Phrase, by id.
-
#before(ref = nil) ⇒ Object
States that this Phrase should only appear before the referenced Phrase, by id.
-
#between(a, b) ⇒ Object
A shorthand for expression both after and before limits.
-
#initialize(*args) ⇒ AnytimePhrase
constructor
A new instance of AnytimePhrase.
Methods included from Conditional::Recur::Phrase
#conditional_recur_tester, included, #recur, #recurs?
Methods inherited from Phrase
#alternately, #instruction, #nothing, #say, #speak
Methods included from Conditional::Registry::Static
#add_prepare, #add_test, #conditional_prepares, #conditional_tests
Methods included from Conditional::Likely::Phrase
Methods included from Conditional::Repeat::Phrase
Methods included from Conditional::Allowed::Phrase
Methods included from Conditional::Registry::Instance
Constructor Details
#initialize(*args) ⇒ AnytimePhrase
Returns a new instance of AnytimePhrase.
180 181 182 |
# File 'lib/madderlib/phrase.rb', line 180 def initialize(*args) super end |
Instance Method Details
#after(ref = nil) ⇒ Object
States that this Phrase should only appear before the referenced Phrase, by id
If the referenced Phrase does not appear in the Builder result, it can appear anywhere
Examples:
flag = true
builder = madderlib do
say 'top'
also(:limit).say('middle').if { flag }
say 'bottom'
anywhere.say('hello').after(:limit)
end
10.times do
words = builder.words
words.index('hello').should eql(2)
end
flag = false
10.times do
words = builder.words
(words.index('hello') > 0).should be_true
end
245 246 247 248 249 250 251 252 253 254 |
# File 'lib/madderlib/phrase.rb', line 245 def after(ref=nil) if ref # settter @after = ref self else # getter @after end end |
#before(ref = nil) ⇒ Object
States that this Phrase should only appear before the referenced Phrase, by id
If the referenced Phrase does not appear in the Builder result, it can appear anywhere
Examples:
flag = true
builder = madderlib do
say 'top'
also(:limit).say('middle').if { flag }
say 'bottom'
anywhere.say('hello').before(:limit)
end
10.times do
words = builder.words
words.index('hello').should eql(1)
end
flag = false
10.times do
words = builder.words
(words.index('hello') < 2).should be_true
end
210 211 212 213 214 215 216 217 218 219 |
# File 'lib/madderlib/phrase.rb', line 210 def before(ref=nil) if ref # settter @before = ref self else # getter @before end end |
#between(a, b) ⇒ Object
A shorthand for expression both after and before limits
The first argument is for after, the second is for before
Examples:
builder = madderlib do
say 'top'
also(:upper).say('upper')
also(:lower).say('lower')
say 'bottom'
anywhere.say('hello').between(:upper, :lower)
end
10.times do
words = builder.words
words.index('hello').should eql(2)
end
274 275 276 277 278 |
# File 'lib/madderlib/phrase.rb', line 274 def between(a, b) after a before b self end |