10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/scene_toolkit/cli/auto_rename.rb', line 10
def self.match(name)
response = Nestful.get("http://www.google.com/search", :params => {:q => name, :num => 100})
response = Nokogiri::HTML(response).search(".g").text.encode("utf-8", "utf-8", :invalid => :replace)
if name =~ /[\d+]$/ regex = /#{Regexp.escape(name)}(?:-[A-Za-z0-9]+)*/i
matches = response.scan(regex).reject(&:downcase?).reject { |m| m.size == name.size }.uniq
else regex = /#{Regexp.escape(name)}/i
matches = response.scan(regex).reject(&:downcase?).select { |m| m.size == name.size }.uniq
end
matches.reject { |m| m == name }.select { |m| m =~ Release::Validations::Name::REGEXP }
end
|