Class: Hx::Path::Pattern

Inherits:
Object
  • Object
show all
Includes:
Selector
Defined in:
lib/hx/path.rb

Instance Method Summary collapse

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

Returns:

  • (Boolean)


82
# File 'lib/hx/path.rb', line 82

def accept_path?(path) ; !!(path =~ @regexp) ; end

#literal?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/hx/path.rb', line 78

def literal?
  @is_literal
end