class Rerun::Glob
Constants
- END_OF_STRING
- NO_LEADING_DOT
- START_OF_FILENAME
Public Class Methods
new(glob_string)
click to toggle source
# File lib/rerun/glob.rb, line 11 def initialize glob_string @glob_string = glob_string end
Public Instance Methods
smoosh(chars)
click to toggle source
# File lib/rerun/glob.rb, line 70 def smoosh chars out = [] until chars.empty? char = chars.shift if char == "*" and chars.first == "*" chars.shift chars.shift if chars.first == "/" out.push("**") else out.push(char) end end out end
to_regexp()
click to toggle source
# File lib/rerun/glob.rb, line 66 def to_regexp Regexp.new(to_regexp_string) end
to_regexp_string()
click to toggle source
# File lib/rerun/glob.rb, line 15 def to_regexp_string chars = @glob_string.split('') chars = smoosh(chars) curlies = 0 escaping = false string = chars.map do |char| if escaping escaping = false char else case char when '**' "([^/]+/)*" when '*' ".*" when "?" "." when "." "\\." when "{" curlies += 1 "(" when "}" if curlies > 0 curlies -= 1 ")" else char end when "," if curlies > 0 "|" else char end when "\\" escaping = true "\\" else char end end end.join START_OF_FILENAME + string + END_OF_STRING end