Class: ProgramR::Condition

Inherits:
AimlTag
  • Object
show all
Defined in:
lib/programr/aiml_elements.rb

Direct Known Subclasses

ConditionItem, ListCondition

Instance Method Summary collapse

Methods inherited from AimlTag

#inspect, #to_s

Constructor Details

#initialize(someAttributes, environment) ⇒ Condition

Returns a new instance of Condition.


101
102
103
104
105
106
107
108
# File 'lib/programr/aiml_elements.rb', line 101

def initialize someAttributes, environment
  @environment = environment
  @conditions = {}
  pick_condition someAttributes do |name, value|
    @property = name
    @currentCondition = value
  end
end

Instance Method Details

#add(aBody) ⇒ Object


110
111
112
113
114
115
# File 'lib/programr/aiml_elements.rb', line 110

def add aBody
  unless @conditions[@currentCondition]
    @conditions[@currentCondition] = []
  end
  @conditions[@currentCondition].push(aBody)
end

#condition_valid?Boolean

Returns:

  • (Boolean)

128
129
130
131
132
133
134
135
136
137
138
# File 'lib/programr/aiml_elements.rb', line 128

def condition_valid?
  if @property.nil?
    false
  elsif @environment.get(@property).nil?
    @currentCondition.nil?
  elsif @environment.get(@property) =~ /^#{@currentCondition}$/
    true
  else
    false
  end
end

#executeObject


124
125
126
# File 'lib/programr/aiml_elements.rb', line 124

def execute
  condition_valid? ? text : ''
end

#setListElement(someAttributes) ⇒ Object


117
118
119
120
121
122
# File 'lib/programr/aiml_elements.rb', line 117

def setListElement someAttributes
  pick_condition someAttributes do |name, value|
    @property = name
    @currentCondition = value
  end
end