Class: ProgramR::ConditionItem

Inherits:
Condition show all
Defined in:
lib/programr/aiml_elements.rb

Instance Method Summary collapse

Methods inherited from Condition

#add, #condition_valid?, #setListElement

Methods inherited from AimlTag

#inspect, #to_s

Constructor Details

#initialize(someAttributes, conditionContainer, environment) ⇒ ConditionItem

Returns a new instance of ConditionItem.


205
206
207
208
209
210
211
212
213
214
215
# File 'lib/programr/aiml_elements.rb', line 205

def initialize someAttributes, conditionContainer, environment
  @conditionContainer = conditionContainer
  @conditions = {}
  @environment = environment
  if @conditionContainer.is_a? ListCondition
    pick_condition someAttributes do |name, value|
      @property = name || @conditionContainer.property
      @currentCondition = value
    end
  end
end

Instance Method Details

#default_item?Boolean

Returns:

  • (Boolean)

217
218
219
# File 'lib/programr/aiml_elements.rb', line 217

def default_item?
  @property.nil? && @currentCondition.nil?
end

#executeObject


221
222
223
224
225
226
227
# File 'lib/programr/aiml_elements.rb', line 221

def execute
  if @conditionContainer.is_a?(Random) or default_item?
    text
  else
    super
  end
end

#to_inspectObject


229
230
231
232
233
234
235
# File 'lib/programr/aiml_elements.rb', line 229

def to_inspect
  if default_item?
    text
  else
    "if #{@property} == #{@currentCondition} then #{text}"
  end
end