Class: Glaemscribe::API::CSubPostProcessorOperator
- Inherits:
-
PostProcessorOperator
- Object
- PrePostProcessorOperator
- PostProcessorOperator
- Glaemscribe::API::CSubPostProcessorOperator
- Defined in:
- lib/api/post_processor/csub.rb
Instance Attribute Summary collapse
-
#matcher ⇒ Object
readonly
Returns the value of attribute matcher.
-
#triggers ⇒ Object
readonly
Returns the value of attribute triggers.
Attributes inherited from PrePostProcessorOperator
Instance Method Summary collapse
- #apply(tokens) ⇒ Object
-
#initialize(args) ⇒ CSubPostProcessorOperator
constructor
A new instance of CSubPostProcessorOperator.
Methods inherited from PrePostProcessorOperator
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
#matcher ⇒ Object (readonly)
Returns the value of attribute matcher.
27 28 29 |
# File 'lib/api/post_processor/csub.rb', line 27 def matcher @matcher end |
#triggers ⇒ Object (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 |