Class: Gloo::Verbs::Unless

Inherits:
Core::Verb show all
Defined in:
lib/gloo/verbs/unless.rb

Constant Summary collapse

KEYWORD =
'unless'.freeze
KEYWORD_SHORT =
'if!'.freeze
DO =
'do'.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

#params, #tokens

Attributes inherited from Core::Baseo

#name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Core::Verb

#display_value, help, inherited, #initialize, #type_display

Methods inherited from Core::Baseo

#initialize, #type_display

Constructor Details

This class inherits a constructor from Gloo::Core::Verb

Class Method Details

.doc_dataObject

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
# File 'lib/gloo/verbs/unless.rb', line 112

def self.doc_data
  {
    :name => KEYWORD,
    :shortcut => KEYWORD_SHORT,
    :description => "Unless an expression is true, do something. " \
      "This is the opposite of the if verb.",
    :syntax => [
      'unless {true} do {command}',
      'unless {true} do {command} else {else command}'
    ],
    :parameters => [
      '{true} — Does the expression evaluate to true?',
      '{command} — Execute command if the expression is false.',
      '{else command} — The else command is optional. Execute else command if the expression is true.'
    ],
    :result => 'Unchanged if the expression is true. If not true, ' \
      'then the result will be based on the command specified ' \
      'after the do 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
      #
      # Unless statement example
      #

      unless [container] :

        x [bool] : true
        false_msg [string] : It is NOT true!

        on_load [script] :
          unless unless.x do show "first time: " + unless.false_msg
          unless ^.x do show 'F' else show 'T'

          put false into unless.x
          unless unless.x do show "second time: " +  unless.false_msg
          unless ^.x do show 'F' else show 'T'
    EXAMPLES
  }
end

.keywordObject

Get the Verb's keyword.



37
38
39
# File 'lib/gloo/verbs/unless.rb', line 37

def self.keyword
  return KEYWORD
end

.keyword_shortcutObject

Get the Verb's keyword shortcut.



44
45
46
# File 'lib/gloo/verbs/unless.rb', line 44

def self.keyword_shortcut
  return KEYWORD_SHORT
end

Instance Method Details

#runObject

Run the verb.



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/gloo/verbs/unless.rb', line 20

def run
  value = value_tokens
  return if value.nil?

  @do = @tokens.expr_after( DO, ELSE )
  @else = @tokens.expr_after( ELSE )

  if evals_false( value )
    run_do
  else
    run_else unless @else.blank?
  end
end