Class: JsRegex::Converter::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/js_regex/converter/base.rb

Overview

Template class. Implement #convert_data in subclasses.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target, context) ⇒ Base

Returns a new instance of Base.



11
12
13
14
# File 'lib/js_regex/converter/base.rb', line 11

def initialize(target, context)
  @target = target
  @context = context
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



9
10
11
# File 'lib/js_regex/converter/base.rb', line 9

def context
  @context
end

#targetObject (readonly)

Returns the value of attribute target.



9
10
11
# File 'lib/js_regex/converter/base.rb', line 9

def target
  @target
end

Instance Method Details

#convert(token_class, subtype, data, start_index, end_index) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/js_regex/converter/base.rb', line 16

def convert(token_class, subtype, data, start_index, end_index)
  self.token_class = token_class
  self.subtype = subtype
  self.data = data
  self.start_index = start_index
  self.end_index = end_index

  result = convert_data
  target.source << (context.valid? ? result : '')
end