-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.rb
56 lines (44 loc) · 1.15 KB
/
utils.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# require 'open-uri'
# require 'nokogiri'
module Utils
def Utils.weight_search_keyword(word, name)
ignores = ['machine']
word = word.downcase
name = name.downcase
ignores.each do |w|
word.gsub!(w, '')
name.gsub!(w, '')
end
if name.include? word
return 10
end
weight = 0
words = word.split(' ').sort
names = name.split(' ').sort
names.each do |name|
words.each do |word|
if name == word
weight += 1
end
end
end
weight
end
# def parsing_product(url)
# p = {}
# doc = Nokogiri::HTML(open(url))
# p[:name] = doc.css('h1.fn').text
# p[:category] = doc.css('.ui-breadcrumb').first['content'].split('>').map(&:strip)
# p[:photos] = [doc.css('.photo.pic.J-pic').first['src']]
# index = 0
# p[:attrs] = []
# attr_v = doc.css('.J-value')
# doc.css('.J-name').each do |k|
# p[:attrs].push [k.text.strip[0..-2], attr_v[index].text.strip]
# index += 1
# end
# p[:consignment_term] = doc.css('td:contains("Packaging Detail:") + td').first.text
# p[:packaging_desc] = doc.css('td:contains("Delivery Detail:") + td').first.text
# p[:summary] = doc.css('p.description').first.text
# end
end