Class: Nearmiss::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/nearmiss-ruby/project.rb

Overview

Class to parse GitHub repository owner and name from URLs and to generate URLs

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project) ⇒ Project

Returns a new instance of Project.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/nearmiss-ruby/project.rb', line 16

def initialize(project)
  case project
  # when Integer
  #   @id = project
  when String
    @id = project
    # @owner, @name = repo.split('/')
    # unless @owner && @name
    #   raise ArgumentError, "Invalid Repository. Use user/repo format."
    # end
  when Project
    @id   = project.id
    # @name = repo.name
  when Hash
    @id = project[:project] ||= project[:id]
    # @owner = repo[:owner] ||= repo[:user] ||= repo[:username]
  end
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



6
7
8
# File 'lib/nearmiss-ruby/project.rb', line 6

def id
  @id
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/nearmiss-ruby/project.rb', line 6

def name
  @name
end

#ownerObject

Returns the value of attribute owner.



6
7
8
# File 'lib/nearmiss-ruby/project.rb', line 6

def owner
  @owner
end

Class Method Details

.from_url(url) ⇒ Repository

Instantiate from a GitHub repository URL

Returns:

  • (Repository)


11
12
13
# File 'lib/nearmiss-ruby/project.rb', line 11

def self.from_url(url)
  Project.new(URI.parse(url).path[1..-1])
end

.path(project) ⇒ String

Get the api path for a repo

Parameters:

  • project (Integer, String, Hash, Project)

    A project.

Returns:

  • (String)

    Api path.



51
52
53
# File 'lib/nearmiss-ruby/project.rb', line 51

def self.path(project)
  new(project).path
end

Instance Method Details

#id_api_pathString

Returns Api path for id identified repos.

Returns:

  • (String)

    Api path for id identified repos



61
62
63
# File 'lib/nearmiss-ruby/project.rb', line 61

def id_api_path
  "projects/#{@id}"
end

#pathString

Returns Project API path.

Returns:

  • (String)

    Project API path



43
44
45
46
# File 'lib/nearmiss-ruby/project.rb', line 43

def path
  # return named_api_path if @owner && @name
  return id_api_path if @id
end

#slugString Also known as: to_s

Project owner/name

Returns:

  • (String)


37
38
39
# File 'lib/nearmiss-ruby/project.rb', line 37

def slug
  # "#{@owner}/#{@name}"
end

#urlString

Project URL based on Client#web_endpoint

Returns:

  • (String)


67
68
69
# File 'lib/nearmiss-ruby/project.rb', line 67

def url
  # "#{Octokit.web_endpoint}#{slug}"
end