Sha256: c9fc3d4aed724a9b40d786e5bef11a477eef5a99ad341f43f1578b5ef7d9f429

Contents?: true

Size: 920 Bytes

Versions: 6

Compression:

Stored size: 920 Bytes

Contents

module JekyllGithubSample
  class FileHelper

    GITHUB_RAW_URI = 'https://raw.githubusercontent.com/'
    GITHUB_URI     = 'https://github.com/'
    WEB_URI_PART = 'blob'

    attr_reader :filename, :user, :project_name

    def initialize(path)
      @path = path
      parts = @path.split('/').delete_if { |e| e.empty? }
      if parts.include? WEB_URI_PART
        @user, @project_name, @blob, @commitish_or_branch = parts[0..3]
        @filename = File.join(parts[4..-1])
      else
        @user, @project_name, @commitish_or_branch = parts[0..2]
        @filename = File.join(parts[3..-1])
      end
    end

    def user_uri
      File.join(GITHUB_URI, @user)
    end

    def web_uri
      File.join(GITHUB_URI, @user, @project_name, WEB_URI_PART, @commitish_or_branch, @filename)
    end

    def raw_uri
      File.join(GITHUB_RAW_URI, @user, @project_name, @commitish_or_branch, @filename)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
jekyll_github_sample-0.3.2 lib/jekyll_github_sample/file_helper.rb
jekyll_github_sample-0.3.1 lib/jekyll_github_sample/file_helper.rb
jekyll_github_sample-0.3.0 lib/jekyll_github_sample/file_helper.rb
jekyll_github_sample-0.2.0 lib/jekyll_github_sample/file_helper.rb
jekyll_github_sample-0.1.1 lib/jekyll_github_sample/file_helper.rb
jekyll_github_sample-0.1.0 lib/jekyll_github_sample/file_helper.rb