81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
# File 'lib/sync-strings.rb', line 81
def find(dir, ignore_list)
paths = []
ignore_list = ignore_list || []
Find.find(dir) do |path|
paths << path if path =~ /.*\.strings$/ && ignore_list.none? { |ignore| path.include? ignore }
end
def split_path(path)
path.split(File::SEPARATOR).reject(&:empty?)
end
paths_hashed_by_base_path = paths.reduce({}) { |acc, path|
base_path = split_path(path)[0...-2].join("/")
if acc.key?(base_path)
acc[base_path].push(path)
elsif
acc[base_path] = [path]
end
acc
}
paths_by_length_and_name = []
paths_hashed_by_base_path.each { |key, same_length_paths|
same_name = []
same_length_paths.each { |same_length_path|
i = same_name.index { |array|
array.any? { |v|
name = split_path(v).last
same_length_path_name = split_path(same_length_path).last
name == same_length_path_name
}
}
if i.nil?
same_name.push([same_length_path])
elsif
same_name[i].push(same_length_path)
end
}
same_name.each{ |entry|
paths_by_length_and_name.push(entry)
}
}
paths_by_length_and_name
end
|