Class: Kanpachi::ResponseList

Inherits:
Object
  • Object
show all
Defined in:
lib/kanpachi/response_list.rb

Overview

Class to keep track of all defined responses

Defined Under Namespace

Classes: DuplicateResponse

Instance Method Summary collapse

Constructor Details

#initializeResponseList

Returns a new instance of ResponseList.



8
9
10
# File 'lib/kanpachi/response_list.rb', line 8

def initialize
  @list = {}
end

Instance Method Details

#add(response) ⇒ Hash<Kanpachi::Response>

Add a response to the list

Parameters:

Returns:

Raises:

  • DuplicateResponse If a response is being duplicated.



34
35
36
37
38
39
# File 'lib/kanpachi/response_list.rb', line 34

def add(response)
  if @list.key? response.name
    raise DuplicateResponse, "A response named #{response.name} already exists"
  end
  @list[response.name] = response
end

#allArray<Kanpachi::Response>

Returns an array of responses

Returns:



24
25
26
# File 'lib/kanpachi/response_list.rb', line 24

def all
  @list.values
end

#find(name) ⇒ Nil, Kanpachi::Response

Returns a response based on its verb and url

Parameters:

  • name (String)

    The name of the response you are looking for.

Returns:



47
48
49
# File 'lib/kanpachi/response_list.rb', line 47

def find(name)
  @list[name]
end

#to_hashHash<Kanpachi::Response>

Returns a hash of responses

Returns:



16
17
18
# File 'lib/kanpachi/response_list.rb', line 16

def to_hash
  @list
end