Class: Gloo::Verbs::If
- Inherits:
-
Core::Verb
- Object
- Core::Baseo
- Core::Verb
- Gloo::Verbs::If
- Defined in:
- lib/gloo/verbs/if.rb
Constant Summary collapse
- KEYWORD =
'if'.freeze
- KEYWORD_SHORT =
'if'.freeze
- THEN =
'then'.freeze
- ELSE =
'else'.freeze
- MISSING_EXPR_ERR =
'Missing Expression!'.freeze
Constants inherited from Core::Baseo
Core::Baseo::NOT_IMPLEMENTED_ERR
Instance Attribute Summary
Attributes inherited from Core::Verb
Attributes inherited from Core::Baseo
Class Method Summary collapse
-
.doc_data ⇒ Object
Get the verb's documentation data.
-
.keyword ⇒ Object
Get the Verb's keyword.
-
.keyword_shortcut ⇒ Object
Get the Verb's keyword shortcut.
Instance Method Summary collapse
-
#run ⇒ Object
Run the verb.
Methods inherited from Core::Verb
#display_value, help, inherited, #initialize, #type_display
Methods inherited from Core::Baseo
Constructor Details
This class inherits a constructor from Gloo::Core::Verb
Class Method Details
.doc_data ⇒ Object
Get the verb's documentation data.
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/gloo/verbs/if.rb', line 112 def self.doc_data { :name => KEYWORD, :shortcut => KEYWORD_SHORT, :description => 'If an expression is true then do something.', :syntax => [ 'if {true} then {do}', 'if {true} then {do} else {do else}' ], :parameters => [ '{true} — Does the expression evaluate to true?', '{do} — Execute command if the expression is true.', '{do else} — The else command is optional. Execute command if the expression is false.' ], :result => 'Unchanged if the expression is not true. If true, ' \ 'then the result will be based on the command specified ' \ 'after the then keyword.', :errors => [ "#{MISSING_EXPR_ERR} — No expression is provided as parameter to the verb.", 'Other errors depend on the command that is run.' ], :examples => <<~EXAMPLES.strip # # If statement example # if [container] : x [bool] : false true_msg [string] : It is true! on_load [script] : if if.x then show "first time: " + if.true_msg if ^.x then show 'T' else show 'F' put true into if.x if if.x \\ then show "second time: " + if.true_msg if ^.x \\ then show 'T' \\ else show 'F' EXAMPLES } end |
.keyword ⇒ Object
Get the Verb's keyword.
37 38 39 |
# File 'lib/gloo/verbs/if.rb', line 37 def self.keyword return KEYWORD end |
.keyword_shortcut ⇒ Object
Get the Verb's keyword shortcut.
44 45 46 |
# File 'lib/gloo/verbs/if.rb', line 44 def self.keyword_shortcut return KEYWORD_SHORT end |
Instance Method Details
#run ⇒ Object
Run the verb.
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/gloo/verbs/if.rb', line 20 def run value = value_tokens return if value.nil? @then = @tokens.expr_after( THEN, ELSE ) @else = @tokens.expr_after( ELSE ) if evals_true( value ) run_then else run_else unless @else.blank? end end |