Class: Repos::RubyToolBoxData

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

Instance Method Summary collapse

Constructor Details

#initialize(gem_name) ⇒ RubyToolBoxData

Returns a new instance of RubyToolBoxData.



219
220
221
222
223
224
# File 'lib/repocrawler/crawler.rb', line 219

def initialize(gem_name)
  @user_agent = ENV['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



227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/repocrawler/crawler.rb', line 227

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