class Repos::RubyToolBoxData

Public Class Methods

new(gem_name, user_agent) click to toggle source
# File lib/repocrawler/crawler.rb, line 355
def initialize(gem_name, user_agent)
  @user_agent = user_agent
  @RUBY_TOOLBOX_BASE_URL = "https://www.ruby-toolbox.com/projects/"
  @RANKING_PATH = "//div[@class='teaser-bar']//li[last()-1]//a"
  @gem_name = gem_name
end

Public Instance Methods

get_ranking() click to toggle source

get the ranking on Ruby ToolBox

# File lib/repocrawler/crawler.rb, line 363
def get_ranking
  begin
    document = open(@RUBY_TOOLBOX_BASE_URL + @gem_name,
        'User-Agent' => @user_agent
      )
    noko_document = Nokogiri::HTML(document)
    ranking = noko_document.xpath(@RANKING_PATH).text
  rescue
    ranking = 0
  end
  ranking
end