Class: WiseGopher::RawParam
- Inherits:
-
Object
- Object
- WiseGopher::RawParam
- Defined in:
- lib/wise_gopher/raw_param.rb
Overview
Register query’s raw_params and interpolate string in query
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#optional ⇒ Object
readonly
Returns the value of attribute optional.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#suffix ⇒ Object
readonly
Returns the value of attribute suffix.
Instance Method Summary collapse
-
#initialize(name, optional: false, default: nil, prefix: nil, suffix: nil) ⇒ RawParam
constructor
A new instance of RawParam.
- #optional? ⇒ Boolean
- #to_s(string = nil) ⇒ Object
Constructor Details
#initialize(name, optional: false, default: nil, prefix: nil, suffix: nil) ⇒ RawParam
Returns a new instance of RawParam.
8 9 10 11 12 13 14 |
# File 'lib/wise_gopher/raw_param.rb', line 8 def initialize(name, optional: false, default: nil, prefix: nil, suffix: nil) @name = name.to_s.freeze @optional = optional @default = default @prefix = prefix.to_s.freeze @suffix = suffix.to_s.freeze end |
Instance Attribute Details
#default ⇒ Object (readonly)
Returns the value of attribute default.
6 7 8 |
# File 'lib/wise_gopher/raw_param.rb', line 6 def default @default end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/wise_gopher/raw_param.rb', line 6 def name @name end |
#optional ⇒ Object (readonly)
Returns the value of attribute optional.
6 7 8 |
# File 'lib/wise_gopher/raw_param.rb', line 6 def optional @optional end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
6 7 8 |
# File 'lib/wise_gopher/raw_param.rb', line 6 def prefix @prefix end |
#suffix ⇒ Object (readonly)
Returns the value of attribute suffix.
6 7 8 |
# File 'lib/wise_gopher/raw_param.rb', line 6 def suffix @suffix end |
Instance Method Details
#optional? ⇒ Boolean
26 27 28 |
# File 'lib/wise_gopher/raw_param.rb', line 26 def optional? optional || !!default end |
#to_s(string = nil) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/wise_gopher/raw_param.rb', line 16 def to_s(string = nil) raise ::ArgumentError, "value required" unless string || optional? content = string || default return "#{prefix}#{content}#{suffix}" if content "" end |