Class: Worklog::Github::Repository
- Inherits:
-
Struct
- Object
- Struct
- Worklog::Github::Repository
- Defined in:
- lib/github/repository.rb
Overview
Represents a GitHub repository with an owner and name.
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#owner ⇒ Object
Returns the value of attribute owner.
Class Method Summary collapse
-
.from_url(url) ⇒ Hash?
Extracts the repository name and owner from a GitHub repository URL.
Instance Method Summary collapse
-
#to_s ⇒ String
Returns a string representation of the repository in the format “owner/name”.
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name
7 8 9 |
# File 'lib/github/repository.rb', line 7 def name @name end |
#owner ⇒ Object
Returns the value of attribute owner
7 8 9 |
# File 'lib/github/repository.rb', line 7 def owner @owner end |
Class Method Details
.from_url(url) ⇒ Hash?
Extracts the repository name and owner from a GitHub repository URL.
18 19 20 21 22 23 24 |
# File 'lib/github/repository.rb', line 18 def self.from_url(url) match = url.match(%r{github\.com[:/](?<owner>[^/]+)/(?<repo>[^/]+)(?:\.git)?$}) match = url.match(%r{^(?<owner>[^/]+)/(?<repo>[^/]+)$}) if match.nil? return nil if match.nil? Repository.new(owner: match[:owner], name: match[:repo]) end |
Instance Method Details
#to_s ⇒ String
Returns a string representation of the repository in the format “owner/name”.
28 29 30 |
# File 'lib/github/repository.rb', line 28 def to_s "#{owner}/#{name}" end |