class ReadmeScore::Document::Loader::GithubReadmeFinder

Constants

POSSIBLE_README_FILES

Public Class Methods

new(github_repo_url) click to toggle source
# File lib/readme-score/document/loader/github_readme_finder.rb, line 9
def initialize(github_repo_url)
  @repo_url = github_repo_url
end

Public Instance Methods

find_url() click to toggle source
# File lib/readme-score/document/loader/github_readme_finder.rb, line 13
def find_url
  uri = URI.parse(@repo_url)
  uri.scheme = "https"
  uri.host = "raw.githubusercontent.com"
  original_path = uri.path
  readme_url = nil
  POSSIBLE_README_FILES.each {|f|
    uri.path = File.join(original_path, "master/#{f}")
    readme_url = uri.to_s if reachable?(uri.to_s)
    break if readme_url
  }
  readme_url
end

Private Instance Methods

reachable?(url) click to toggle source
# File lib/readme-score/document/loader/github_readme_finder.rb, line 28
def reachable?(url)
  begin
    RestClient::Request.execute(method: :head, url: url)
    true
  rescue RestClient::Exception
    false
  end
end