Class: Locomotive::Wagon::Glob
- Inherits:
-
Object
- Object
- Locomotive::Wagon::Glob
- Defined in:
- lib/locomotive/wagon/tools/glob.rb
Constant Summary collapse
- NO_LEADING_DOT =
todo
'(?=[^\.])'- START_OF_FILENAME =
beginning of string or a slash
'(\A|\/)'- END_OF_STRING =
'\z'
Instance Method Summary collapse
-
#initialize(glob_string) ⇒ Glob
constructor
A new instance of Glob.
- #smoosh(chars) ⇒ Object
- #to_regexp ⇒ Object
- #to_regexp_string ⇒ Object
Constructor Details
#initialize(glob_string) ⇒ Glob
Returns a new instance of Glob.
14 15 16 |
# File 'lib/locomotive/wagon/tools/glob.rb', line 14 def initialize(glob_string) @glob_string = glob_string end |
Instance Method Details
#smoosh(chars) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# 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 ⇒ Object
25 26 27 |
# File 'lib/locomotive/wagon/tools/glob.rb', line 25 def to_regexp Regexp.new(to_regexp_string) end |
#to_regexp_string ⇒ Object
18 19 20 21 22 23 |
# 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 |