Module: Rosette::Core::PathMatcherFactory::NodeFactory

Included in:
Rosette::Core::PathMatcherFactory, Node
Defined in:
lib/rosette/core/path_matcher_factory.rb

Overview

Provides common methods for creating nodes.

Instance Method Summary collapse

Instance Method Details

#match_file_extension(extension) ⇒ FileExtensionNode

Creates a FileExtensionNode.

Parameters:

  • extension (String)

    The file extension to match.

Returns:


54
55
56
# File 'lib/rosette/core/path_matcher_factory.rb', line 54

def match_file_extension(extension)
  FileExtensionNode.new(extension)
end

#match_file_extensions(extensions) ⇒ FileExtensionNode, OrNode

Creates a bunch of FileExtensionNodes combined using a logical “or”.

Parameters:

  • extensions (Array<String>)

    A list of file extensions.

Returns:

  • (FileExtensionNode, OrNode)

    the root node of a tree of all the file extensions specified in extensions. Each file extension will be wrapped in a FileExtensionNode and logically “or”ed together. If extensions only contains one file extension, then this method just returns an instance of FileExtensionNode. If extensions contains more than one entry, this method returns an OrNode.


67
68
69
70
71
72
# File 'lib/rosette/core/path_matcher_factory.rb', line 67

def match_file_extensions(extensions)
  Array(extensions).inject(nil) do |node, extension|
    new_node = match_file_extension(extension)
    node ? node.or(new_node) : new_node
  end
end

#match_path(path) ⇒ PathNode

Creates a PathNode.

Parameters:

  • path (String)

    The path to match.

Returns:


78
79
80
# File 'lib/rosette/core/path_matcher_factory.rb', line 78

def match_path(path)
  PathNode.new(path)
end

#match_paths(paths) ⇒ PathNode, OrNode

Creates a bunch of PathNodes combined using a logical “or”.

Parameters:

  • paths (Array<String>)

    A list of paths.

Returns:

  • (PathNode, OrNode)

    the root of a tree of all the paths specified in paths. Each path will be wrapped in a PathNode and logically “or”ed together. If paths only contains one path, then this method just returns an instance of PathNode. If paths contains more than one entry, this method returns an OrNode.


90
91
92
93
94
95
# File 'lib/rosette/core/path_matcher_factory.rb', line 90

def match_paths(paths)
  Array(paths).inject(nil) do |node, path|
    new_node = match_path(path)
    node ? node.or(new_node) : new_node
  end
end

#match_regex(regex) ⇒ RegexNode

Creates a RegexNode.

Parameters:

  • regex (Regexp)

    The regex to match.

Returns:


101
102
103
# File 'lib/rosette/core/path_matcher_factory.rb', line 101

def match_regex(regex)
  RegexNode.new(regex)
end

#match_regexes(regexes) ⇒ RegexNode, OrNode

Creates a bunch of RegexNodes combined using a logical “or”.

Parameters:

  • regexes (Array<Regexp>)

    A list of regular expressions.

Returns:

  • (RegexNode, OrNode)

    the root of a tree of all the regexes specified in regexes. Each regex will be wrapped in a RegexNode and logically “or”ed together. If regexes only contains one entry, then this method just returns an instance of RegexNode. If regexes contains more than one entry, this method returns an OrNode.


113
114
115
116
117
118
# File 'lib/rosette/core/path_matcher_factory.rb', line 113

def match_regexes(regexes)
  Array(regexes).inject(nil) do |node, regex|
    new_node = match_regex(regex)
    node ? node.or(new_node) : new_node
  end
end