Class: Kanpachi::ResponseList
- Inherits:
-
Object
- Object
- Kanpachi::ResponseList
- 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
-
#add(response) ⇒ Hash<Kanpachi::Response>
Add a response to the list.
-
#all ⇒ Array<Kanpachi::Response>
Returns an array of responses.
-
#find(name) ⇒ Nil, Kanpachi::Response
Returns a response based on its verb and url.
-
#initialize ⇒ ResponseList
constructor
A new instance of ResponseList.
-
#to_hash ⇒ Hash<Kanpachi::Response>
Returns a hash of responses.
Constructor Details
#initialize ⇒ ResponseList
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
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 |
#all ⇒ Array<Kanpachi::Response>
Returns an array of responses
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
47 48 49 |
# File 'lib/kanpachi/response_list.rb', line 47 def find(name) @list[name] end |
#to_hash ⇒ Hash<Kanpachi::Response>
Returns a hash of responses
16 17 18 |
# File 'lib/kanpachi/response_list.rb', line 16 def to_hash @list end |