Method: Dir#real_name

Defined in:
lib/rmtools/fs/dir.rb

#real_nameObject

Fixing windoze path problems requires amatch gem for better performance



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/rmtools/fs/dir.rb', line 78

def real_name
  n, p, count = name, parent, []
  return n if !p
  pp, pc, sc = parent.path, parent.to_a[2..-1], to_a
  if defined? Amatch
    ms = pc.sizes.max
    count = [:hamming_similar, :levenshtein_similar, :jaro_similar].sum {|m| pc.group_by {|_| _.upcase.ljust(ms).send(m, n)}.max[1]}.count.to_a
    max = count.lasts.max
    res = count.find {|c|
      c[1] == max and File.directory?(df=File.join(pp, c[0])) and Dir.new(df).to_a == sc
    }
    return res[0] if res
  end
  (pc - count).find {|c|
    File.directory?(df=File.join(pp, c)) and Dir.new(df).to_a == sc
  }
end