Class: Repos::RubyToolBoxData
- Inherits:
-
Object
- Object
- Repos::RubyToolBoxData
- Defined in:
- lib/repocrawler/crawler.rb
Instance Method Summary collapse
-
#get_ranking ⇒ Object
get the ranking on Ruby ToolBox.
-
#initialize(gem_name, user_agent) ⇒ RubyToolBoxData
constructor
A new instance of RubyToolBoxData.
Constructor Details
#initialize(gem_name, user_agent) ⇒ RubyToolBoxData
Returns a new instance of RubyToolBoxData.
334 335 336 337 338 339 |
# File 'lib/repocrawler/crawler.rb', line 334 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_ranking ⇒ Object
get the ranking on Ruby ToolBox
342 343 344 345 346 347 348 349 350 351 352 353 |
# File 'lib/repocrawler/crawler.rb', line 342 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 |