Class: HaveAPI::Client::Parameters::Typed

Inherits:
Object
  • Object
show all
Defined in:
lib/haveapi/client/parameters/typed.rb

Defined Under Namespace

Modules: Boolean

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params, desc, value) ⇒ Typed

Returns a new instance of Typed.



21
22
23
24
25
26
# File 'lib/haveapi/client/parameters/typed.rb', line 21

def initialize(params, desc, value)
  @params = params
  @desc = desc
  @errors = []
  @value = coerce(value)
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



19
20
21
# File 'lib/haveapi/client/parameters/typed.rb', line 19

def errors
  @errors
end

#valueObject (readonly)

Returns the value of attribute value.



19
20
21
# File 'lib/haveapi/client/parameters/typed.rb', line 19

def value
  @value
end

Instance Method Details

#to_apiObject



35
36
37
38
39
40
41
42
# File 'lib/haveapi/client/parameters/typed.rb', line 35

def to_api
  if @desc[:type] == 'Datetime' && value.is_a?(Time)
    value.iso8601

  else
    value
  end
end

#valid?Boolean

Returns:



28
29
30
31
32
33
# File 'lib/haveapi/client/parameters/typed.rb', line 28

def valid?
  ret = Validator.validate(@desc[:validators], @value, @params)

  @errors.concat(ret) unless ret === true
  ret === true
end