Class: Toolhound::Incident
- Inherits:
-
Object
- Object
- Toolhound::Incident
- 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
-
#id ⇒ Object
Returns the value of attribute id.
Class Method Summary collapse
-
.from_url(url) ⇒ Incident
Instantiate from a incident URL.
-
.path(incident) ⇒ String
Get the api path for a repo.
Instance Method Summary collapse
-
#id_api_path ⇒ String
Api path for id identified incidents.
-
#initialize(incident) ⇒ Incident
constructor
A new instance of Incident.
-
#path ⇒ String
Incident API path.
-
#slug ⇒ String
(also: #to_s)
Incident owner/name.
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
#id ⇒ Object
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
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
51 52 53 |
# File 'lib/toolhound-ruby/incident.rb', line 51 def self.path(incident) new(incident).path end |
Instance Method Details
#id_api_path ⇒ String
Returns Api path for id identified incidents.
61 62 63 |
# File 'lib/toolhound-ruby/incident.rb', line 61 def id_api_path "incidents/#{@id}" end |
#path ⇒ String
Returns 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 |
#slug ⇒ String Also known as: to_s
Incident owner/name
37 38 39 |
# File 'lib/toolhound-ruby/incident.rb', line 37 def slug # "#{@owner}/#{@name}" end |