Class: Colloquy::Node
- Inherits:
-
Object
show all
- Defined in:
- lib/colloquy/node.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(identifier = :index, options = {}, &block) ⇒ Node
Returns a new instance of Node.
5
6
7
8
9
10
11
|
# File 'lib/colloquy/node.rb', line 5
def initialize(identifier = :index, options = {}, &block)
@identifier = identifier.to_sym
@flow = options[:flow] || nil
@options = options.delete(:flow)
instance_eval &block if block
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *arguments, &block) ⇒ Object
39
40
41
42
43
44
45
|
# File 'lib/colloquy/node.rb', line 39
def method_missing(method, *arguments, &block)
if @flow and @flow.respond_to? method
@flow.send(method, *arguments, &block)
else
raise NoMethodError, "#{method} is missing in the flow"
end
end
|
Instance Attribute Details
#flow=(value) ⇒ Object
3
4
5
|
# File 'lib/colloquy/node.rb', line 3
def flow=(value)
@flow = value
end
|
#identifier ⇒ Object
Returns the value of attribute identifier.
2
3
4
|
# File 'lib/colloquy/node.rb', line 2
def identifier
@identifier
end
|
#options ⇒ Object
Returns the value of attribute options.
2
3
4
|
# File 'lib/colloquy/node.rb', line 2
def options
@options
end
|
Instance Method Details
25
26
27
|
# File 'lib/colloquy/node.rb', line 25
def
@menu ||= Colloquy::Menu.new(:flow => @flow)
end
|
21
22
23
|
# File 'lib/colloquy/node.rb', line 21
def
@menu && !@menu.empty?
end
|
#process(&block) ⇒ Object
55
56
57
|
# File 'lib/colloquy/node.rb', line 55
def process(&block)
@process_block = block
end
|
#process!(input = nil) ⇒ Object
59
60
61
|
# File 'lib/colloquy/node.rb', line 59
def process!(input = nil)
@process_block.call(input) if @process_block
end
|
#prompt(message) ⇒ Object
13
14
15
|
# File 'lib/colloquy/node.rb', line 13
def prompt(message)
@prompt = Colloquy::Prompt.new(:message => message, :flow => @flow)
end
|
#prompt? ⇒ Boolean
17
18
19
|
# File 'lib/colloquy/node.rb', line 17
def prompt?
@prompt && !@prompt.blank?
end
|
#render ⇒ Object
29
30
31
32
33
34
35
36
37
|
# File 'lib/colloquy/node.rb', line 29
def render
if @prompt
@prompt.render
elsif !.empty?
.render
else
""
end.strip
end
|
#request(&block) ⇒ Object
47
48
49
|
# File 'lib/colloquy/node.rb', line 47
def request(&block)
@request_block = block
end
|
#request!(input = nil) ⇒ Object
51
52
53
|
# File 'lib/colloquy/node.rb', line 51
def request!(input = nil)
@request_block.call(input) if @request_block
end
|
#reset! ⇒ Object
63
64
65
66
|
# File 'lib/colloquy/node.rb', line 63
def reset!
@prompt = nil
.reset!
end
|