class Alparser::Branc
Public Instance Methods
all_club_climbs(year: nil)
click to toggle source
# File lib/alparser/branc.rb, line 15 def all_club_climbs year: nil out = club_climbs(year: year) number_of_pages, i = @number_of_pages, 2 while i <= number_of_pages out = out + club_climbs(page: i, year: year) i += 1 end out end
climb_from(item)
click to toggle source
# 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 # Noting 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
club_climbs(page:1, year: nil)
click to toggle source
# File lib/alparser/branc.rb, line 4 def club_climbs page:1, year: nil response = self.class.get "/vzponi-vse.php", query: { page: page, leto: (year.nil? ? Time.now.year : year) } handle_page_number response handle_climbs response end
handle_climbs(response)
click to toggle source
# File lib/alparser/branc.rb, line 27 def handle_climbs response response.parsed_response.xpath("//table[@bgcolor='silver']/tr[position()>1]").to_a.map! do |item| climb_from item end end
handle_page_number(response)
click to toggle source
# File lib/alparser/branc.rb, line 33 def handle_page_number response @number_of_pages ||= 0 # puts "handle_page_number" @number_of_pages = response.parsed_response.xpath("//a[@class='pagebox']/span").to_a.last.text.gsub!(/[^a-z0-9\-_]+/, "").to_i # @number_of_pages = ((/^\<span\>.(\d+)/.match(response.parsed_response.xpath("//a[@class='pagebox']/span").to_a.last.to_s))[1].to_i) rescue 1 end