Class: HaveAPI::Client::Parameters::Typed
- Inherits:
-
Object
- Object
- HaveAPI::Client::Parameters::Typed
- Defined in:
- lib/haveapi/client/parameters/typed.rb
Defined Under Namespace
Modules: Boolean
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(params, desc, value) ⇒ Typed
constructor
A new instance of Typed.
- #to_api ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(params, desc, value) ⇒ Typed
Returns a new instance of Typed.
19 20 21 22 23 24 |
# File 'lib/haveapi/client/parameters/typed.rb', line 19 def initialize(params, desc, value) @params = params @desc = desc @errors = [] @value = coerce(value) end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
17 18 19 |
# File 'lib/haveapi/client/parameters/typed.rb', line 17 def errors @errors end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
17 18 19 |
# File 'lib/haveapi/client/parameters/typed.rb', line 17 def value @value end |
Instance Method Details
#to_api ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/haveapi/client/parameters/typed.rb', line 33 def to_api if @desc[:type] == 'Datetime' && value.is_a?(Time) value.iso8601 else value end end |
#valid? ⇒ Boolean
26 27 28 29 30 31 |
# File 'lib/haveapi/client/parameters/typed.rb', line 26 def valid? ret = Validator.validate(@desc[:validators], @value, @params) @errors.concat(ret) unless ret === true ret === true end |