Class: ConfigTemplates::Criteria::Name

Inherits:
Object
  • Object
show all
Defined in:
lib/config_templates/criteria/name.rb

Instance Method Summary collapse

Constructor Details

#initialize(pattern, straight = true) ⇒ Name

Returns a new instance of Name.



3
4
5
6
# File 'lib/config_templates/criteria/name.rb', line 3

def initialize(pattern, straight = true)
  @pattern = pattern
  @straight = straight
end

Instance Method Details

#cast(expression) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/config_templates/criteria/name.rb', line 12

def cast(expression)
  if expression.is_a?(::String) || expression.is_a?(::Regexp)
    expression
  else
    expression.to_s
  end
end

#matches?(expression) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/config_templates/criteria/name.rb', line 8

def matches?(expression)
  @pattern.match?(cast expression) && @straight
end