Class: Toolhound::Incident

Inherits:
Object
  • Object
show all
Defined in:
lib/toolhound-ruby/incident.rb

Overview

Class to parse incident owner and name from URLs and to generate URLs

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(incident) ⇒ Incident

Returns a new instance of Incident.



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

def initialize(incident)
  case incident
  # when Integer
  #   @id = incident
  when String
    @id = incident
    # @owner, @name = repo.split('/')
    # unless @owner && @name
    #   raise ArgumentError, "Invalid Incident. Use user/repo format."
    # end
  when Incident
    @id   = incident.id
    # @name = repo.name
  when Hash
    @id = incident[:incident] ||= incident[: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/toolhound-ruby/incident.rb', line 6

def id
  @id
end

Class Method Details

.from_url(url) ⇒ Incident

Instantiate from a incident URL

Returns:



11
12
13
# File 'lib/toolhound-ruby/incident.rb', line 11

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

.path(incident) ⇒ String

Get the api path for a repo

Parameters:

Returns:



51
52
53
# File 'lib/toolhound-ruby/incident.rb', line 51

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

Instance Method Details

#id_api_pathString

Returns Api path for id identified incidents.

Returns:

  • (String)

    Api path for id identified incidents



61
62
63
# File 'lib/toolhound-ruby/incident.rb', line 61

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

#pathString

Returns Incident API path.

Returns:

  • (String)

    Incident API path



43
44
45
46
# File 'lib/toolhound-ruby/incident.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

Incident owner/name

Returns:



37
38
39
# File 'lib/toolhound-ruby/incident.rb', line 37

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