Class: Rosette::Core::PathMatcherFactory::PathNode

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

Overview

Matches paths.

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(path) ⇒ PathNode

Creates a new path node.

Parameters:

  • path (String)

    The path to match.


275
276
277
# File 'lib/rosette/core/path_matcher_factory.rb', line 275

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathString (readonly)

Returns the path to match.

Returns:

  • (String)

    the path to match.


269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
# File 'lib/rosette/core/path_matcher_factory.rb', line 269

class PathNode < Node
  attr_reader :path

  # Creates a new path node.
  #
  # @param [String] path The path to match.
  def initialize(path)
    @path = path
  end

  # Determines if the given path matches +path+.
  #
  # @param [String] match_path The path to match.
  # @return [Boolean] true if +match_path+ matches +path+, false otherwise.
  #   Matching is done by comparing the first +n+ characters of +match_path+
  #   to +path+, where +n+ is the number of characters in +path+. In other words,
  #   if +path+ is "/path/to" and +match_path+ is '/path/to/foo.rb', this method
  #   will return true.
  def matches?(match_path)
    match_path[0...path.size] == path
  end

  # Generates a string representation of this node.
  #
  # @return [String]
  def to_s
    "matches_path('#{path}')"
  end
end

Instance Method Details

#matches?(match_path) ⇒ Boolean

Determines if the given path matches path.

Parameters:

  • match_path (String)

    The path to match.

Returns:

  • (Boolean)

    true if match_path matches path, false otherwise. Matching is done by comparing the first n characters of match_path to path, where n is the number of characters in path. In other words, if path is “/path/to” and match_path is '/path/to/foo.rb', this method will return true.


287
288
289
# File 'lib/rosette/core/path_matcher_factory.rb', line 287

def matches?(match_path)
  match_path[0...path.size] == path
end

#to_sString

Generates a string representation of this node.

Returns:

  • (String)

294
295
296
# File 'lib/rosette/core/path_matcher_factory.rb', line 294

def to_s
  "matches_path('#{path}')"
end