Class: Glaemscribe::API::CSubPostProcessorOperator

Inherits:
PostProcessorOperator show all
Defined in:
lib/api/post_processor/csub.rb

Instance Attribute Summary collapse

Attributes inherited from PrePostProcessorOperator

#args, #raw_args

Instance Method Summary collapse

Methods inherited from PrePostProcessorOperator

#eval_arg, #finalize

Constructor Details

#initialize(args) ⇒ CSubPostProcessorOperator

Returns a new instance of CSubPostProcessorOperator.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/api/post_processor/csub.rb', line 30

def initialize(args)
  super(args)
  
  # Build our operator
  @matcher     = self.raw_args[0]
  @triggers    = Hash.new
  
  self.raw_args.each{ |arg|

    splitted  = arg.split()   
    replacer  = splitted.shift()
    
    splitted.each{ |token|
      @triggers[token] = replacer
    }
  }
end

Instance Attribute Details

#matcherObject (readonly)

Returns the value of attribute matcher.



27
28
29
# File 'lib/api/post_processor/csub.rb', line 27

def matcher
  @matcher
end

#triggersObject (readonly)

Returns the value of attribute triggers.



28
29
30
# File 'lib/api/post_processor/csub.rb', line 28

def triggers
  @triggers
end

Instance Method Details

#apply(tokens) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/api/post_processor/csub.rb', line 48

def apply(tokens)
  last_trigger_replacer = nil
  tokens.each_with_index{ |token,idx|
    if token == @matcher && last_trigger_replacer != nil
      tokens[idx] = last_trigger_replacer
    elsif @triggers[token] != nil
      last_trigger_replacer = @triggers[token]
    end
  }
  tokens
end