Class: Rosette::Core::PathMatcherFactory::RegexNode
- Defined in:
- lib/rosette/core/path_matcher_factory.rb
Overview
Determines if the given path matches regex.
Instance Attribute Summary collapse
-
#regex ⇒ Regex
readonly
The regex to match with.
Instance Method Summary collapse
-
#initialize(regex) ⇒ RegexNode
constructor
Creates a new regex node.
-
#matches?(path) ⇒ Boolean
Determines if
regexmatches the given path. -
#to_s ⇒ String
Generates a string representation of this node.
Methods included from NodeOperatorFactory
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.
309 310 311 |
# File 'lib/rosette/core/path_matcher_factory.rb', line 309 def initialize(regex) @regex = regex end |
Instance Attribute Details
#regex ⇒ Regex (readonly)
Returns 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.
317 318 319 |
# File 'lib/rosette/core/path_matcher_factory.rb', line 317 def matches?(path) !!(path =~ regex) end |
#to_s ⇒ String
Generates a string representation of this node.
324 325 326 |
# File 'lib/rosette/core/path_matcher_factory.rb', line 324 def to_s "matches_regex(/#{regex.source}/)" end |