Class: Hx::Path::Pattern
Instance Method Summary collapse
- #accept_path?(path) ⇒ Boolean
-
#initialize(tokens) ⇒ Pattern
constructor
A new instance of Pattern.
- #literal? ⇒ Boolean
Methods included from Selector
#&, #assume_circumfix, #elide_circumfix, #|, #~
Constructor Details
#initialize(tokens) ⇒ Pattern
Returns a new instance of Pattern.
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/hx/path.rb', line 67 def initialize(tokens) @is_literal = tokens.size == 1 and String === tokens.first @regexp = Regexp.new("^#{tokens.map { |token| case token when :doublestar; '.*' when :star; '[^/]*' else; Regexp.quote(token) end }}$") end |
Instance Method Details
#accept_path?(path) ⇒ Boolean
82 |
# File 'lib/hx/path.rb', line 82 def accept_path?(path) ; !!(path =~ @regexp) ; end |
#literal? ⇒ Boolean
78 79 80 |
# File 'lib/hx/path.rb', line 78 def literal? @is_literal end |