Class: HaveAPI::Client::Parameters::Typed
- Inherits:
-
Object
- Object
- HaveAPI::Client::Parameters::Typed
- Defined in:
- lib/haveapi/client/parameters/typed.rb
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.
7 8 9 10 11 12 |
# File 'lib/haveapi/client/parameters/typed.rb', line 7 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.
5 6 7 |
# File 'lib/haveapi/client/parameters/typed.rb', line 5 def errors @errors end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
5 6 7 |
# File 'lib/haveapi/client/parameters/typed.rb', line 5 def value @value end |
Instance Method Details
#to_api ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/haveapi/client/parameters/typed.rb', line 23 def to_api if @desc[:type] == 'Datetime' && value.is_a?(Time) value.iso8601 else value end end |
#valid? ⇒ Boolean
14 15 16 17 18 19 20 21 |
# File 'lib/haveapi/client/parameters/typed.rb', line 14 def valid? return false unless @errors.empty? ret = Validator.validate(@desc[:validators], @value, @params) @errors.concat(ret) unless ret === true ret === true end |