Class: ProgramR::ReplaceTag

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

Direct Known Subclasses

Gender, Person, Person2

Constant Summary collapse

Map =
{}

Instance Method Summary collapse

Methods inherited from AimlTag

#inspect, #to_s

Constructor Details

#initializeReplaceTag

Returns a new instance of ReplaceTag.


385
386
387
# File 'lib/programr/aiml_elements.rb', line 385

def initialize
  @sentence = []
end

Instance Method Details

#add(anObj) ⇒ Object


389
390
391
# File 'lib/programr/aiml_elements.rb', line 389

def add anObj
  @sentence.push anObj
end

#executeObject


393
394
395
396
397
398
399
# File 'lib/programr/aiml_elements.rb', line 393

def execute
  res = @sentence.map(&:to_s).join('').strip
  self.class::Map.each_pair do |matcher, fn|
    res = res.gsub(matcher) { |match| replace fn, $~ }
  end
  res
end