Class: EleetScript::ESRegex

Inherits:
Regexp
  • Object
show all
Defined in:
lib/lang/runtime/base_classes.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pattern, desired_flags = nil) ⇒ ESRegex

Returns a new instance of ESRegex.



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/lang/runtime/base_classes.rb', line 56

def initialize(pattern, desired_flags = nil)
  flag_num = 0
  if desired_flags.is_a?(String)
    flag_set = desired_flags ? Set.new(desired_flags.chars) : []
    @global = true if flag_set.include?('g')
    flag_num |= Regexp::IGNORECASE if flag_set.include?('i')
    flag_num |= Regexp::MULTILINE if flag_set.include?('m')
  else
    flag_num = desired_flags
  end
  super(pattern, flag_num)
end

Instance Attribute Details

#global=(value) ⇒ Object (writeonly)

Sets the attribute global

Parameters:

  • value

    the value to set the attribute global to.



48
49
50
# File 'lib/lang/runtime/base_classes.rb', line 48

def global=(value)
  @global = value
end

Class Method Details

.from_regex(regex) ⇒ Object



51
52
53
# File 'lib/lang/runtime/base_classes.rb', line 51

def from_regex(regex)
  ESRegex.new(regex.source, regex.options)
end

Instance Method Details

#flagsObject



81
82
83
84
85
86
87
# File 'lib/lang/runtime/base_classes.rb', line 81

def flags
  @flags ||= [].tap do |flags|
    flags << 'm' if multiline?
    flags << 'i' if ignorecase?
    flags << 'g' if global?
  end.join('')
end

#global?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/lang/runtime/base_classes.rb', line 69

def global?
  @global || false
end

#ignorecase?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/lang/runtime/base_classes.rb', line 73

def ignorecase?
  options & Regexp::IGNORECASE == Regexp::IGNORECASE
end

#multiline?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/lang/runtime/base_classes.rb', line 77

def multiline?
  options & Regexp::MULTILINE == Regexp::MULTILINE
end