/lib/octokit/gist.rb
Ruby | 36 lines | 20 code | 7 blank | 9 comment | 0 complexity | 8fb3fe79601142b618509f34a36cccfd MD5 | raw file
1module Octokit 2 3 # Class to parse and create Gist URLs 4 class Gist 5 6 # !@attribute id 7 # @return [String] Gist ID 8 attr_accessor :id 9 10 # Instantiate {Gist} object from Gist URL 11 # @ return [Gist] 12 def self.from_url(url) 13 Gist.new(URI.parse(url).path[1..-1]) 14 end 15 16 def initialize(gist) 17 case gist 18 when Integer, String 19 @id = gist.to_s 20 end 21 end 22 23 # Gist ID 24 # @return [String] 25 def to_s 26 @id 27 end 28 29 # Gist URL 30 # @return [String] 31 def url 32 "https://gist.github.com/#{@id}" 33 end 34 35 end 36end