Class: JsRegex::Converter::PropertyConverter

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

Overview

Template class implementation.

Direct Known Subclasses

NonpropertyConverter

Instance Attribute Summary

Attributes inherited from Base

#context, #target

Class Method Summary collapse

Methods inherited from Base

#convert, #initialize

Constructor Details

This class inherits a constructor from JsRegex::Converter::Base

Class Method Details

.negated_property_replacement(property_string) ⇒ Object



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

def self.negated_property_replacement(property_string)
  # take care not to use destructive methods on elements in the map
  return nil unless property_string
  if property_string.start_with?('[^')
    property_string.sub('[^', '[')
  elsif property_string.start_with?('[')
    property_string.sub('[', '[^')
  else
    # it's an invertable meta char
    property_string.swapcase
  end
end

.property_replacement(property_name, negated = false) ⇒ Object



10
11
12
13
# File 'lib/js_regex/converter/property_converter.rb', line 10

def self.property_replacement(property_name, negated = false)
  replacement = JsRegex::PROPERTY_MAP[property_name.downcase.to_sym]
  negated ? negated_property_replacement(replacement) : replacement
end