Class: Repos::RubyToolBoxData

Inherits:
Object
  • Object
show all
Defined in:
lib/repocrawler/crawler.rb

Instance Method Summary collapse

Constructor Details

#initialize(gem_name, user_agent) ⇒ RubyToolBoxData

Returns a new instance of RubyToolBoxData.



355
356
357
358
359
360
# 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

Instance Method Details

#get_rankingObject

get the ranking on Ruby ToolBox



363
364
365
366
367
368
369
370
371
372
373
374
# 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