Class: Goodcheck::Pattern::Regexp

Inherits:
Object
  • Object
show all
Defined in:
lib/goodcheck/pattern.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source:, case_sensitive:, multiline:, regexp: nil) ⇒ Regexp

Returns a new instance of Regexp.



22
23
24
25
26
27
# File 'lib/goodcheck/pattern.rb', line 22

def initialize(source:, case_sensitive:, multiline:, regexp: nil)
  @source = source
  @case_sensitive = case_sensitive
  @multiline = multiline
  @regexp = regexp
end

Instance Attribute Details

#case_sensitiveObject (readonly)

Returns the value of attribute case_sensitive.



19
20
21
# File 'lib/goodcheck/pattern.rb', line 19

def case_sensitive
  @case_sensitive
end

#multilineObject (readonly)

Returns the value of attribute multiline.



20
21
22
# File 'lib/goodcheck/pattern.rb', line 20

def multiline
  @multiline
end

#sourceObject (readonly)

Returns the value of attribute source.



18
19
20
# File 'lib/goodcheck/pattern.rb', line 18

def source
  @source
end

Instance Method Details

#regexpObject



29
30
31
32
33
34
35
36
# File 'lib/goodcheck/pattern.rb', line 29

def regexp
  @regexp ||= begin
    options = 0
    options |= ::Regexp::IGNORECASE unless case_sensitive
    options |= ::Regexp::MULTILINE if multiline
    ::Regexp.compile(source, options)
  end
end