Class: PYR::Param
- Inherits:
-
Object
- Object
- PYR::Param
- Defined in:
- lib/pyr/param.rb
Overview
Defines the #to_s method for request params. Will handle the conversion differently depending on if it is an ID param e.g. controller/:id
Instance Attribute Summary collapse
- #name ⇒ Object readonly
- #value ⇒ Object readonly
Instance Method Summary collapse
-
#id? ⇒ Boolean
Is the param an ID param?.
-
#initialize(name, value, id: nil) ⇒ Param
constructor
Set the param ‘name` and `value`, and whether it’s an ID.
-
#to_s ⇒ Object
Format the param for the URI.
Constructor Details
#initialize(name, value, id: nil) ⇒ Param
Set the param ‘name` and `value`, and whether it’s an ID
12 13 14 15 16 |
# File 'lib/pyr/param.rb', line 12 def initialize(name, value, id: nil) @id = !id.nil? @name = name @value = value end |
Instance Attribute Details
#name ⇒ Object (readonly)
9 10 11 |
# File 'lib/pyr/param.rb', line 9 def name @name end |
#value ⇒ Object (readonly)
9 10 11 |
# File 'lib/pyr/param.rb', line 9 def value @value end |
Instance Method Details
#id? ⇒ Boolean
Is the param an ID param?
19 20 21 |
# File 'lib/pyr/param.rb', line 19 def id? @id end |
#to_s ⇒ Object
Format the param for the URI
24 25 26 27 |
# File 'lib/pyr/param.rb', line 24 def to_s url_value = value.to_s.tr('#;\'""', '').gsub(' ', '%20') id? ? "/#{value}" : "#{name}=#{url_value}" end |