class Locomotive::Wagon::Glob
Constants
- END_OF_STRING
- NO_LEADING_DOT
- START_OF_FILENAME
Public Class Methods
new(glob_string)
click to toggle source
# File lib/locomotive/wagon/tools/glob.rb, line 14 def initialize(glob_string) @glob_string = glob_string end
Public Instance Methods
smoosh(chars)
click to toggle source
# File lib/locomotive/wagon/tools/glob.rb, line 29 def smoosh(chars) [].tap do |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 end end
to_regexp()
click to toggle source
# File lib/locomotive/wagon/tools/glob.rb, line 25 def to_regexp Regexp.new(to_regexp_string) end
to_regexp_string()
click to toggle source
# File lib/locomotive/wagon/tools/glob.rb, line 18 def to_regexp_string chars = @glob_string.split('') chars = smoosh(chars) START_OF_FILENAME + parse(chars) + END_OF_STRING end
Protected Instance Methods
parse(chars)
click to toggle source
# File lib/locomotive/wagon/tools/glob.rb, line 46 def parse(chars) curlies, escaping = 0, false chars.map do |char| if escaping escaping = false char else case char when '**' then "([^/]+/)*" when '*' then ".*" when "?" then "." when "." then "\\." 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 end