Class: CabbageDoc::Params
- Inherits:
-
Object
- Object
- CabbageDoc::Params
- Includes:
- Enumerable
- Defined in:
- lib/cabbage_doc/params.rb
Constant Summary collapse
- ACTION =
'__action'.freeze
- METHOD =
'__method'.freeze
- TAG =
'__tag'.freeze
Instance Method Summary collapse
- #delete(key) ⇒ Object
- #each ⇒ Object
- #find(key) ⇒ Object
-
#initialize(params, collection) ⇒ Params
constructor
A new instance of Params.
- #to_hash ⇒ Object
- #to_query ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(params, collection) ⇒ Params
Returns a new instance of Params.
9 10 11 |
# File 'lib/cabbage_doc/params.rb', line 9 def initialize(params, collection) @_params = convert(params, collection) end |
Instance Method Details
#delete(key) ⇒ Object
19 20 21 |
# File 'lib/cabbage_doc/params.rb', line 19 def delete(key) @_params.delete(key) end |
#each ⇒ Object
13 14 15 16 17 |
# File 'lib/cabbage_doc/params.rb', line 13 def each @_params.each do |k, v| yield(k, v) end end |
#find(key) ⇒ Object
23 24 25 |
# File 'lib/cabbage_doc/params.rb', line 23 def find(key) @_params[key] end |
#to_hash ⇒ Object
31 32 33 |
# File 'lib/cabbage_doc/params.rb', line 31 def to_hash @_params end |
#to_query ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/cabbage_doc/params.rb', line 35 def to_query @_params.map do |k, v| if v.is_a?(Array) v.map { |vv| "#{k}[]=#{CGI.escape(vv)}" } else "#{k}=#{CGI.escape(v)}" end end.flatten.join('&') end |
#valid? ⇒ Boolean
27 28 29 |
# File 'lib/cabbage_doc/params.rb', line 27 def valid? @_params.any? end |