Class: JsRegex
- Inherits:
-
Object
- Object
- JsRegex
- Defined in:
- lib/js_regex.rb,
lib/js_regex/node.rb,
lib/js_regex/error.rb,
lib/js_regex/target.rb,
lib/js_regex/version.rb,
lib/js_regex/converter.rb,
lib/js_regex/conversion.rb,
lib/js_regex/second_pass.rb,
lib/js_regex/converter/base.rb,
lib/js_regex/converter/context.rb,
lib/js_regex/converter/set_converter.rb,
lib/js_regex/converter/keep_converter.rb,
lib/js_regex/converter/meta_converter.rb,
lib/js_regex/converter/type_converter.rb,
lib/js_regex/converter/group_converter.rb,
lib/js_regex/converter/anchor_converter.rb,
lib/js_regex/converter/escape_converter.rb,
lib/js_regex/converter/literal_converter.rb,
lib/js_regex/converter/property_converter.rb,
lib/js_regex/converter/assertion_converter.rb,
lib/js_regex/converter/freespace_converter.rb,
lib/js_regex/converter/conditional_converter.rb,
lib/js_regex/converter/backreference_converter.rb,
lib/js_regex/converter/subexpression_converter.rb,
lib/js_regex/converter/unsupported_token_converter.rb
Overview
JsRegex converts ::Regexp instances to JavaScript.
Usage:
js_regex = JsRegex.new(my_ruby_regex) js_regex.to_h # for use in ‘new RegExp()’ js_regex.to_s # for direct injection into JavaScript
Defined Under Namespace
Modules: Converter, Error, SecondPass, Target Classes: Conversion, Node
Constant Summary collapse
- ConversionError =
Class.new(StandardError).send(:include, JsRegex::Error)
- VERSION =
'3.14.0'
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
-
#warnings ⇒ Object
readonly
Returns the value of attribute warnings.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(ruby_regex, **kwargs) ⇒ JsRegex
constructor
A new instance of JsRegex.
- #to_h ⇒ Object
- #to_json(options = {}) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(ruby_regex, **kwargs) ⇒ JsRegex
Returns a new instance of JsRegex.
19 20 21 |
# File 'lib/js_regex.rb', line 19 def initialize(ruby_regex, **kwargs) @source, , @warnings, @target = Conversion.of(ruby_regex, **kwargs) end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
17 18 19 |
# File 'lib/js_regex.rb', line 17 def end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
17 18 19 |
# File 'lib/js_regex.rb', line 17 def source @source end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
17 18 19 |
# File 'lib/js_regex.rb', line 17 def target @target end |
#warnings ⇒ Object (readonly)
Returns the value of attribute warnings.
17 18 19 |
# File 'lib/js_regex.rb', line 17 def warnings @warnings end |
Class Method Details
.compatible?(ruby_regex, **kwargs) ⇒ Boolean
40 41 42 43 44 45 |
# File 'lib/js_regex.rb', line 40 def self.compatible?(ruby_regex, **kwargs) new!(ruby_regex, **kwargs) true rescue ConversionError false end |
.new!(ruby_regex, **kwargs) ⇒ Object
36 37 38 |
# File 'lib/js_regex.rb', line 36 def self.new!(ruby_regex, **kwargs) new(ruby_regex, fail_fast: true, **kwargs) end |
Instance Method Details
#to_h ⇒ Object
23 24 25 |
# File 'lib/js_regex.rb', line 23 def to_h { source: source, options: } end |
#to_json(options = {}) ⇒ Object
27 28 29 |
# File 'lib/js_regex.rb', line 27 def to_json( = {}) to_h.to_json() end |
#to_s ⇒ Object
31 32 33 |
# File 'lib/js_regex.rb', line 31 def to_s "/#{source.empty? ? '(?:)' : source}/#{options}" end |