Class: Fetch::FormData
- Inherits:
-
Object
- Object
- Fetch::FormData
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/fetch/form_data.rb
Instance Attribute Summary collapse
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
Class Method Summary collapse
Instance Method Summary collapse
- #append(key, value) ⇒ Object
- #delete(key) ⇒ Object
- #get(key) ⇒ Object
- #get_all(key) ⇒ Object
- #has(key) ⇒ Object
-
#initialize ⇒ FormData
constructor
A new instance of FormData.
- #keys ⇒ Object
- #set(key, value) ⇒ Object
- #values ⇒ Object
Constructor Details
#initialize ⇒ FormData
Returns a new instance of FormData.
21 22 23 |
# File 'lib/fetch/form_data.rb', line 21 def initialize @entries = [] end |
Instance Attribute Details
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
25 26 27 |
# File 'lib/fetch/form_data.rb', line 25 def entries @entries end |
Class Method Details
Instance Method Details
#append(key, value) ⇒ Object
27 28 29 |
# File 'lib/fetch/form_data.rb', line 27 def append(key, value) @entries.push [key.to_s, File === value ? value : value.to_s] end |
#delete(key) ⇒ Object
31 32 33 |
# File 'lib/fetch/form_data.rb', line 31 def delete(key) @entries.reject! {|k,| k == key.to_s } end |
#get(key) ⇒ Object
35 36 37 |
# File 'lib/fetch/form_data.rb', line 35 def get(key) @entries.assoc(key.to_s)&.last end |
#get_all(key) ⇒ Object
39 40 41 |
# File 'lib/fetch/form_data.rb', line 39 def get_all(key) @entries.select {|k,| k == key.to_s }.map(&:last) end |
#has(key) ⇒ Object
43 44 45 |
# File 'lib/fetch/form_data.rb', line 43 def has(key) @entries.any? {|k,| k == key.to_s } end |
#keys ⇒ Object
47 48 49 |
# File 'lib/fetch/form_data.rb', line 47 def keys @entries.map(&:first) end |
#set(key, value) ⇒ Object
51 52 53 54 |
# File 'lib/fetch/form_data.rb', line 51 def set(key, value) delete key append key, value end |
#values ⇒ Object
56 57 58 |
# File 'lib/fetch/form_data.rb', line 56 def values @entries.map(&:last) end |