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
79
80
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
|
# File 'lib/alparser/branc.rb', line 41
def climb_from item
date = Date.parse(item.xpath("./td[position()=1]").text)
route = item.xpath("./td[position()=2]/a").text.strip
route ||= item.xpath("./td[position()=2]//b").text.strip
id = nil
if item.xpath("./td[position()=2]/a").first.attributes["href"].to_s =~ /pid=(\d+)$/
id = Integer(Regexp.last_match[1].to_s)
end
if id.nil? and item.xpath("./td[position()=2]/a").first.attributes["href"].to_s =~ /rid=(\d+)$/
id = Integer(Regexp.last_match[1].to_s)
end
mountain_range = item.xpath("./td[position()=3]").text.strip
country = item.xpath("./td[position()=4]").text.lstrip.strip.sub!(/\u00A0/, "")
country ||= item.xpath("./td[position()=4]").text
has_notes = item.xpath("./td[position()=2]/img[@src='ikone/opombe.gif']").size == 1
has_images = item.xpath("./td[position()=2]/img[@src='ikone/fotke.gif']").size == 1
country_id = nil
begin
if item.xpath("./td[position()=4]/img").first.attributes["src"].to_s =~ /\/(\w+)\.gif$/
country_id = Regexp.last_match[1].to_s
end
rescue
end
grade = item.xpath("./td[position()=5]").text
climber = item.xpath("./td[position()=6]/a")
climber_id = nil
if climber.first.attributes["href"].to_s =~ /mem=(\d+)/
climber_id = Regexp.last_match[1].to_i
end
climber = climber.text.strip
conditions = item.xpath("./td[position()=7]").text
kind = item.xpath("./td[position()=8]").text
kind = kind == "" ? nil : kind
climb = Alparser::Climb.new(
id: id,
date: date,
route: route,
mountain_range: mountain_range,
country: country,
country_id: country_id,
grade: grade,
conditions: conditions,
kind: kind,
has_notes: has_notes,
has_images: has_images,
user_name: climber,
user_id: climber_id
)
climb.base_uri = @url
unless climb.user_id.nil?
climb.user = Alparser::User.new(
id: climb.user_id,
name: climb.user_name,
base_uri: @url
)
end
climb
end
|