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.
17 18 19 20 21 22 |
# File 'lib/haveapi/client/parameters/typed.rb', line 17 def initialize(params, desc, value) @params = params @desc = desc @value = coerce(value) @errors = [] end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
15 16 17 |
# File 'lib/haveapi/client/parameters/typed.rb', line 15 def errors @errors end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
15 16 17 |
# File 'lib/haveapi/client/parameters/typed.rb', line 15 def value @value end |
Instance Method Details
#to_api ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/haveapi/client/parameters/typed.rb', line 31 def to_api if @desc[:type] == 'Datetime' && value.is_a?(Time) value.iso8601 else value end end |
#valid? ⇒ Boolean
24 25 26 27 28 29 |
# File 'lib/haveapi/client/parameters/typed.rb', line 24 def valid? ret = Validator.validate(@desc[:validators], @value, @params) @errors.concat(ret) unless ret === true ret === true end |