/lib/octokit/gist.rb

http://github.com/pengwynn/octokit · Ruby · 36 lines · 20 code · 7 blank · 9 comment · 0 complexity · 8fb3fe79601142b618509f34a36cccfd MD5 · raw file

  1. module Octokit
  2. # Class to parse and create Gist URLs
  3. class Gist
  4. # !@attribute id
  5. # @return [String] Gist ID
  6. attr_accessor :id
  7. # Instantiate {Gist} object from Gist URL
  8. # @ return [Gist]
  9. def self.from_url(url)
  10. Gist.new(URI.parse(url).path[1..-1])
  11. end
  12. def initialize(gist)
  13. case gist
  14. when Integer, String
  15. @id = gist.to_s
  16. end
  17. end
  18. # Gist ID
  19. # @return [String]
  20. def to_s
  21. @id
  22. end
  23. # Gist URL
  24. # @return [String]
  25. def url
  26. "https://gist.github.com/#{@id}"
  27. end
  28. end
  29. end