Class: JsRegex::Conversion

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

Overview

This class acts as a facade, creating specific Converters and passing Regexp::Scanner tokens to them, reusing Converters as needed.

::of returns a source String, options String, and warnings Array.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ruby_regex) ⇒ Conversion

Returns a new instance of Conversion.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/js_regex/conversion.rb', line 16

def initialize(ruby_regex)
  self.ruby_regex = ruby_regex

  self.context    = Converter::Context.new
  self.converters = {}

  self.source     = ''.dup
  self.options    = ''.dup
  self.warnings   = []

  convert_source
  convert_options
  perform_sanity_check
end

Instance Attribute Details

#contextObject

Returns the value of attribute context.



14
15
16
# File 'lib/js_regex/conversion.rb', line 14

def context
  @context
end

#convertersObject

Returns the value of attribute converters.



14
15
16
# File 'lib/js_regex/conversion.rb', line 14

def converters
  @converters
end

#optionsObject

Returns the value of attribute options.



14
15
16
# File 'lib/js_regex/conversion.rb', line 14

def options
  @options
end

#ruby_regexObject

Returns the value of attribute ruby_regex.



14
15
16
# File 'lib/js_regex/conversion.rb', line 14

def ruby_regex
  @ruby_regex
end

#sourceObject

Returns the value of attribute source.



14
15
16
# File 'lib/js_regex/conversion.rb', line 14

def source
  @source
end

#warningsObject

Returns the value of attribute warnings.



14
15
16
# File 'lib/js_regex/conversion.rb', line 14

def warnings
  @warnings
end

Class Method Details

.of(ruby_regex) ⇒ Object



31
32
33
34
# File 'lib/js_regex/conversion.rb', line 31

def self.of(ruby_regex)
  conversion = new(ruby_regex)
  [conversion.source, conversion.options, conversion.warnings]
end