class Nearmiss::Incident

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

Attributes

id[RW]

Public Class Methods

from_url(url) click to toggle source

Instantiate from a incident URL

@return [Incident]

# File lib/nearmiss-ruby/incident.rb, line 11
def self.from_url(url)
  Incident.new(URI.parse(url).path[1..-1])
end
new(incident) click to toggle source
# File lib/nearmiss-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
path(incident) click to toggle source

Get the api path for a repo @param incident [Integer, String, Hash, Incident] A incident. @return [String] Api path.

# File lib/nearmiss-ruby/incident.rb, line 51
def self.path(incident)
  new(incident).path
end

Public Instance Methods

id_api_path() click to toggle source

@return [String] Api path for id identified incidents

# File lib/nearmiss-ruby/incident.rb, line 61
def id_api_path
  "incidents/#{@id}"
end
path() click to toggle source

@return [String] Incident API path

# File lib/nearmiss-ruby/incident.rb, line 43
def path
  # return named_api_path if @owner && @name
  return id_api_path if @id
end
slug() click to toggle source

Incident owner/name @return [String]

# File lib/nearmiss-ruby/incident.rb, line 37
def slug
  # "#{@owner}/#{@name}"
end
Also aliased as: to_s
to_s()
Alias for: slug