Class: EleetScript::ESRegex
- Inherits:
-
Regexp
- Object
- Regexp
- EleetScript::ESRegex
- Defined in:
- lib/lang/runtime/base_classes.rb
Instance Attribute Summary collapse
-
#global ⇒ Object
writeonly
Sets the attribute global.
Class Method Summary collapse
Instance Method Summary collapse
- #flags ⇒ Object
- #global? ⇒ Boolean
- #ignorecase? ⇒ Boolean
-
#initialize(pattern, desired_flags = nil) ⇒ ESRegex
constructor
A new instance of ESRegex.
- #multiline? ⇒ Boolean
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
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.) end |
Instance Method Details
#flags ⇒ Object
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
69 70 71 |
# File 'lib/lang/runtime/base_classes.rb', line 69 def global? @global || false end |
#ignorecase? ⇒ Boolean
73 74 75 |
# File 'lib/lang/runtime/base_classes.rb', line 73 def ignorecase? & Regexp::IGNORECASE == Regexp::IGNORECASE end |
#multiline? ⇒ Boolean
77 78 79 |
# File 'lib/lang/runtime/base_classes.rb', line 77 def multiline? & Regexp::MULTILINE == Regexp::MULTILINE end |