Class: JsonApiClient::Schema::Property

Inherits:
Struct
  • Object
show all
Defined in:
lib/json_api_client/schema.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#defaultObject

Returns the value of attribute default

Returns:

  • (Object)

    the current value of default



3
4
5
# File 'lib/json_api_client/schema.rb', line 3

def default
  @default
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



3
4
5
# File 'lib/json_api_client/schema.rb', line 3

def name
  @name
end

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



3
4
5
# File 'lib/json_api_client/schema.rb', line 3

def type
  @type
end

Instance Method Details

#cast(value) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/json_api_client/schema.rb', line 4

def cast(value)
  return nil if value.nil?
  return value if type.nil?

  case type.to_sym
  when :int, :integer
    value.to_i
  when :string
    value.to_s
  when :float
    value.to_f
  when :boolean
    if value.is_a?(String)
      value == "false" ? false : true
    else
      !!value
    end
  else
    value
  end
end