Class: ReadmeScore::Document::Loader::GithubReadmeFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/readme-score/document/loader/github_readme_finder.rb

Constant Summary collapse

POSSIBLE_README_FILES =
%w{README.md readme.md README readme ReadMe ReadMe.md}

Instance Method Summary collapse

Constructor Details

#initialize(github_repo_url) ⇒ GithubReadmeFinder

Returns a new instance of GithubReadmeFinder.



9
10
11
# File 'lib/readme-score/document/loader/github_readme_finder.rb', line 9

def initialize(github_repo_url)
  @repo_url = github_repo_url
end

Instance Method Details

#find_urlObject



13
14
15
16
17
18
19
20
21
22
23
24
25
# 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