Class: Nanoc::Core::Pattern

Inherits:
Object
  • Object
show all
Includes:
ContractsSupport
Defined in:
lib/nanoc/core/pattern.rb

Direct Known Subclasses

RegexpPattern, StringPattern

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ContractsSupport

enabled?, included, setup_once, warn_about_performance

Constructor Details

#initialize(_obj) ⇒ Pattern

Returns a new instance of Pattern.

Raises:

  • (NotImplementedError)


27
28
29
# File 'lib/nanoc/core/pattern.rb', line 27

def initialize(_obj)
  raise NotImplementedError
end

Class Method Details

.from(obj) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/nanoc/core/pattern.rb', line 9

def self.from(obj)
  case obj
  when Nanoc::Core::StringPattern, Nanoc::Core::RegexpPattern
    obj
  when String
    Nanoc::Core::StringPattern.new(obj)
  when Regexp
    Nanoc::Core::RegexpPattern.new(obj)
  when Symbol
    Nanoc::Core::StringPattern.new(obj.to_s)
  else
    raise(
      ArgumentError,
      "Do not know how to convert `#{obj.inspect}` into a Nanoc::Pattern",
    )
  end
end

Instance Method Details

#===(other) ⇒ Object



36
37
38
# File 'lib/nanoc/core/pattern.rb', line 36

def ===(other)
  match?(other)
end

#captures(_identifier) ⇒ Object

Raises:

  • (NotImplementedError)


40
41
42
# File 'lib/nanoc/core/pattern.rb', line 40

def captures(_identifier)
  raise NotImplementedError
end

#match?(_identifier) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


31
32
33
# File 'lib/nanoc/core/pattern.rb', line 31

def match?(_identifier)
  raise NotImplementedError
end