Class: Nanoc::Core::RegexpPattern

Inherits:
Pattern
  • Object
show all
Defined in:
lib/nanoc/core/regexp_pattern.rb

Instance Method Summary collapse

Methods inherited from Pattern

from

Methods included from ContractsSupport

enabled?, included, setup_once, warn_about_performance

Constructor Details

#initialize(regexp) ⇒ RegexpPattern

Returns a new instance of RegexpPattern.



7
8
9
# File 'lib/nanoc/core/regexp_pattern.rb', line 7

def initialize(regexp)
  @regexp = regexp
end

Instance Method Details

#captures(identifier) ⇒ Object



17
18
19
20
# File 'lib/nanoc/core/regexp_pattern.rb', line 17

def captures(identifier)
  matches = @regexp.match(identifier.to_s)
  matches&.captures
end

#match?(identifier) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/nanoc/core/regexp_pattern.rb', line 12

def match?(identifier)
  (identifier.to_s =~ @regexp) != nil
end

#to_sObject



23
24
25
# File 'lib/nanoc/core/regexp_pattern.rb', line 23

def to_s
  @regexp.to_s
end