lib/octopussy/repo.rb in octopussy-0.0.1 vs lib/octopussy/repo.rb in octopussy-0.1.0

- old
+ new

@@ -1,33 +1,49 @@ -class Repo - attr_accessor :username, :name +module Octopussy + class Repo + attr_accessor :username, :name - def initialize(repo) - if repo.is_a?(String) - repo = repo.split("/") - @name = repo.pop - @username = repo.pop - elsif repo.is_a?(Repo) - @username = repo.username - @name = repo.name - elsif repo.is_a?(Hash) - @name = repo[:repo] ||= repo[:name] - @username = repo[:username] ||= repo[:user] ||= repo[:owner] + def initialize(repo) + if repo.is_a?(String) + repo = repo.split("/") + @name = repo.pop + @username = repo.pop + elsif repo.is_a?(Repo) + @username = repo.username + @name = repo.name + elsif repo.is_a?(Hash) + @name = repo[:repo] ||= repo[:name] + @username = repo[:username] ||= repo[:user] ||= repo[:owner] + end end - end - def slug - "#{@username}/#{@name}" - end + def slug + "#{@username}/#{@name}" + end - def user - @username - end + def to_s + self.slug + end - def repo - @name - end + def url + "http://github.com/#{slug}" + end - def user=(val) - @username = val + def user + @username + end + + def repo + @name + end + + def user=(val) + @username = val + end + + def self.from_url(url) + return if url.nil? + username, name = url.gsub("http://github.com/", "").split("/") + Repo.new("#{username}/#{name}") + end end end \ No newline at end of file