Class: Rosette::Core::PathMatcherFactory::RegexNode

Inherits:
Node
  • Object
show all
Defined in:
lib/rosette/core/path_matcher_factory.rb

Overview

Determines if the given path matches regex.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from NodeOperatorFactory

#and, #not, #or

Methods included from NodeFactory

#match_file_extension, #match_file_extensions, #match_path, #match_paths, #match_regex, #match_regexes

Constructor Details

#initialize(regex) ⇒ RegexNode

Creates a new regex node.

Parameters:

  • regex (Regex)

    The regex to match with.


309
310
311
# File 'lib/rosette/core/path_matcher_factory.rb', line 309

def initialize(regex)
  @regex = regex
end

Instance Attribute Details

#regexRegex (readonly)

Returns The regex to match with.

Returns:

  • (Regex)

    The regex to match with.


303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
# File 'lib/rosette/core/path_matcher_factory.rb', line 303

class RegexNode < Node
  attr_reader :regex

  # Creates a new regex node.
  #
  # @param [Regex] regex The regex to match with.
  def initialize(regex)
    @regex = regex
  end

  # Determines if +regex+ matches the given path.
  #
  # @param [String] path The path to match.
  # @return [Boolean] true if +regex+ matches +path+, false otherwise.
  def matches?(path)
    !!(path =~ regex)
  end

  # Generates a string representation of this node.
  #
  # @return [String]
  def to_s
    "matches_regex(/#{regex.source}/)"
  end
end

Instance Method Details

#matches?(path) ⇒ Boolean

Determines if regex matches the given path.

Parameters:

  • path (String)

    The path to match.

Returns:

  • (Boolean)

    true if regex matches path, false otherwise.


317
318
319
# File 'lib/rosette/core/path_matcher_factory.rb', line 317

def matches?(path)
  !!(path =~ regex)
end

#to_sString

Generates a string representation of this node.

Returns:

  • (String)

324
325
326
# File 'lib/rosette/core/path_matcher_factory.rb', line 324

def to_s
  "matches_regex(/#{regex.source}/)"
end