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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/metal_archives/parsers/label.rb', line 17
def parse(response)
props = {
name: nil,
contact: [],
address: nil,
country: nil,
phone: nil,
status: nil,
specialization: [],
date_founded: nil,
online_shopping: nil,
}
doc = Nokogiri::HTML(response)
props[:name] = doc.css("#label_info .label_name").first.content
doc.css("#label_contact a").each do |contact|
props[:contact] << {
title: contact.content,
content: contact.attr(:href),
}
end
doc.css("#label_info dl").each do |dl|
dl.search("dt").each do |dt|
content = sanitize(dt.next_element.content)
next if content == "N/A"
case sanitize(dt.content)
when "Address:"
props[:address] = content
when "Country:"
props[:country] = Country.parse(css("a").first.content)
when "Phone number:"
props[:phone] = content
when "Status:"
props[:status] = content.downcase.tr(" ", "_").to_sym
when "Specialised in:"
props[:specializations] = Parsers::Genre.parse(content)
when "Founding date :"
props[:date_founded] = Parsers::Date.parse(content)
when "Sub-labels:"
when "Online shopping:"
case content
when "Yes"
props[:online_shopping] = true
when "No"
props[:online_shopping] = false
end
else
raise "Unknown token: #{dt.content}"
end
end
end
props
end
|