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.



14
15
16
17
18
19
20
21
22
23
# File 'lib/js_regex/conversion.rb', line 14

def initialize(ruby_regex)
  @ruby_regex = ruby_regex
  @source = ''
  @options = ''
  @warnings = []

  convert_source(ruby_regex)
  convert_options(ruby_regex)
  perform_sanity_check
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



12
13
14
# File 'lib/js_regex/conversion.rb', line 12

def options
  @options
end

#ruby_regexObject (readonly)

Returns the value of attribute ruby_regex.



12
13
14
# File 'lib/js_regex/conversion.rb', line 12

def ruby_regex
  @ruby_regex
end

#sourceObject (readonly)

Returns the value of attribute source.



12
13
14
# File 'lib/js_regex/conversion.rb', line 12

def source
  @source
end

#warningsObject (readonly)

Returns the value of attribute warnings.



12
13
14
# File 'lib/js_regex/conversion.rb', line 12

def warnings
  @warnings
end

Class Method Details

.of(ruby_regex) ⇒ Object



25
26
27
28
# File 'lib/js_regex/conversion.rb', line 25

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