Class: Rosette::Core::PathMatcherFactory::FileExtensionNode
- Defined in:
- lib/rosette/core/path_matcher_factory.rb
Overview
Matches file extensions.
Instance Attribute Summary collapse
-
#extension ⇒ String
readonly
The extension to match.
Instance Method Summary collapse
-
#initialize(extension) ⇒ FileExtensionNode
constructor
Creates a new file extension node.
-
#matches?(path) ⇒ Boolean
Determines if the given path’s file extension matches
extension. -
#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(extension) ⇒ FileExtensionNode
Creates a new file extension node.
243 244 245 |
# File 'lib/rosette/core/path_matcher_factory.rb', line 243 def initialize(extension) @extension = extension end |
Instance Attribute Details
#extension ⇒ String (readonly)
Returns the extension to match.
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/rosette/core/path_matcher_factory.rb', line 237 class FileExtensionNode < Node attr_reader :extension # Creates a new file extension node. # # @param [String] extension The extension to match. def initialize(extension) @extension = extension end # Determines if the given path's file extension matches +extension+. # # @param [String] path The path to match. # @return [Boolean] true if the path matches +extension+, false otherwise. def matches?(path) # avoid using File.extname to allow matching against double extensions, # eg. file.html.erb path[-extension.size..-1] == extension end # Generates a string representation of this node. # # @return [String] def to_s "has_file_extension('#{extension}')" end end |
Instance Method Details
#matches?(path) ⇒ Boolean
Determines if the given path’s file extension matches extension.
251 252 253 254 255 |
# File 'lib/rosette/core/path_matcher_factory.rb', line 251 def matches?(path) # avoid using File.extname to allow matching against double extensions, # eg. file.html.erb path[-extension.size..-1] == extension end |
#to_s ⇒ String
Generates a string representation of this node.
260 261 262 |
# File 'lib/rosette/core/path_matcher_factory.rb', line 260 def to_s "has_file_extension('#{extension}')" end |