class GemStatictic
Attributes
gem_name[R]
Public Class Methods
new(gem_name)
click to toggle source
# File lib/top_gems.rb, line 11 def initialize(gem_name) @gem_name = gem_name[0] end
Public Instance Methods
create_stat()
click to toggle source
# File lib/top_gems.rb, line 15 def create_stat parse = { gem_name: gem_name, used_by: find_used_by, watch_by: find_wath_by, stars: find_stars, forks: find_forks, contributors: find_contributors, open_issues: find_issues } p parse end
Private Instance Methods
downgload_html()
click to toggle source
# File lib/top_gems.rb, line 43 def downgload_html @downgload_html ||= Nokogiri.HTML(::Kernel.open(find_repo)) end
downgload_used_html()
click to toggle source
# File lib/top_gems.rb, line 47 def downgload_used_html @downgload_used_html ||= Nokogiri.HTML(::Kernel.open("#{find_repo}/network/dependents")) end
find_contributors()
click to toggle source
# File lib/top_gems.rb, line 67 def find_contributors downgload_html.css("span[class='num text-emphasized']")[-1].text.tr('^0-9', '').to_i end
find_forks()
click to toggle source
# File lib/top_gems.rb, line 63 def find_forks downgload_html.css("a[class='social-count']")[1].text.tr('^0-9', '').to_i end
find_issues()
click to toggle source
# File lib/top_gems.rb, line 71 def find_issues downgload_html.css("span[class='Counter']")[0].text.tr('^0-9', '').to_i end
find_repo()
click to toggle source
def gem?
url = "https://rubygems.org/api/v1/gems/#{gem_name}.json" HTTParty.get(url).parsed_response['name'].nil?
end
# File lib/top_gems.rb, line 35 def find_repo # raise StandardError if gem? url = "https://#{AUTH_TOKEN}@api.github.com/search/repositories?q=#{gem_name}&per_page=1" HTTParty.get(url).parsed_response['items'][0]['html_url'].to_s # rescue StandardError => e # puts "ERR: [#{gem_name}] gem could not be found." end
find_stars()
click to toggle source
# File lib/top_gems.rb, line 59 def find_stars downgload_html.css("a[class='social-count js-social-count']").text.tr('^0-9', '').to_i end
find_used_by()
click to toggle source
# File lib/top_gems.rb, line 51 def find_used_by downgload_used_html.css('.btn-link').css('.selected').text.tr('^0-9', '').to_i end
find_wath_by()
click to toggle source
# File lib/top_gems.rb, line 55 def find_wath_by downgload_html.css("a[class='social-count']")[0].text.tr('^0-9', '').to_i end