Class: ProgramR::Condition
- Inherits:
-
Object
- Object
- ProgramR::Condition
- Defined in:
- lib/programr/aiml_elements.rb
Direct Known Subclasses
Constant Summary collapse
- @@environment =
se c’e’ * nel value?
Environment.new
Instance Method Summary collapse
- #add(aBody) ⇒ Object
- #execute ⇒ Object (also: #to_s)
-
#initialize(someAttributes) ⇒ Condition
constructor
A new instance of Condition.
- #inspect ⇒ Object
- #setListElement(someAttributes) ⇒ Object
Constructor Details
#initialize(someAttributes) ⇒ Condition
Returns a new instance of Condition.
85 86 87 88 89 |
# File 'lib/programr/aiml_elements.rb', line 85 def initialize(someAttributes) @conditions = {} @property = someAttributes['name'] @currentCondition = someAttributes['value'].sub('*','.*') end |
Instance Method Details
#add(aBody) ⇒ Object
91 92 93 94 95 96 |
# File 'lib/programr/aiml_elements.rb', line 91 def add(aBody) unless @conditions[@currentCondition] @conditions[@currentCondition] = [] end @conditions[@currentCondition].push(aBody) end |
#execute ⇒ Object Also known as: to_s
106 107 108 109 110 111 112 113 |
# File 'lib/programr/aiml_elements.rb', line 106 def execute return '' unless(@@environment.get(@property) =~ /^#{@currentCondition}$/) res = '' @conditions[@currentCondition].each{|tocken| res += tocken.to_s } return res.strip end |
#inspect ⇒ Object
115 116 117 |
# File 'lib/programr/aiml_elements.rb', line 115 def inspect() "condition -> #{execute}" end |
#setListElement(someAttributes) ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/programr/aiml_elements.rb', line 98 def setListElement(someAttributes) @property = someAttributes['name'] if(someAttributes.key?('name')) @currentCondition = '_default' if(someAttributes.key?('value')) @currentCondition = someAttributes['value'].sub('*','.*') end end |