Class: Middleman::WebP::PathnameMatcher
- Inherits:
-
Object
- Object
- Middleman::WebP::PathnameMatcher
- Includes:
- Comparable
- Defined in:
- lib/middleman-webp/pathname_matcher.rb
Instance Attribute Summary collapse
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Compares matchers based on their preciness.
- #hash ⇒ Object
-
#initialize(pattern = '**/*') ⇒ PathnameMatcher
constructor
Initializes matcher with given pattern.
-
#matches?(path) ⇒ Boolean
Checks given file against pattern.
Constructor Details
#initialize(pattern = '**/*') ⇒ PathnameMatcher
Initializes matcher with given pattern.
pattern - Pattern to match pathnames against to. May be
string, glob, prog or regex.
11 12 13 |
# File 'lib/middleman-webp/pathname_matcher.rb', line 11 def initialize(pattern = '**/*') @pattern = pattern end |
Instance Attribute Details
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
5 6 7 |
# File 'lib/middleman-webp/pathname_matcher.rb', line 5 def pattern @pattern end |
Instance Method Details
#<=>(other) ⇒ Object
Compares matchers based on their preciness.
-
One with longest pattern is considered to be more precise
-
Glob or Regexp patterns are considered more precise than procs.
28 29 30 31 32 33 |
# File 'lib/middleman-webp/pathname_matcher.rb', line 28 def <=>(other) is_proc_involed = other.pattern.respond_to?(:call) || @pattern.respond_to?(:call) return compare_to_proc(other) if is_proc_involed @pattern.to_s.length <=> other.pattern.to_s.length end |
#hash ⇒ Object
35 36 37 |
# File 'lib/middleman-webp/pathname_matcher.rb', line 35 def hash @pattern.hash end |
#matches?(path) ⇒ Boolean
Checks given file against pattern.
file - File, Pathname or String
18 19 20 21 22 |
# File 'lib/middleman-webp/pathname_matcher.rb', line 18 def matches?(path) return false if path.nil? send match_method, Pathname.new(path) end |