Class: OData::Int16Type

Inherits:
PrimitiveType show all
Defined in:
lib/odata/types/primitive_types/int_16_type.rb

Instance Method Summary collapse

Methods inherited from Type

#collection?, #initialize

Constructor Details

This class inherits a constructor from OData::Type

Instance Method Details

#coerce(value) ⇒ Object

Raises:

  • (TypeError)

9
10
11
12
13
# File 'lib/odata/types/primitive_types/int_16_type.rb', line 9

def coerce(value)
  val = value.respond_to?(:to_i) ? value.to_i : value
  raise TypeError, "Cannot convert #{value.inspect} into an Int16" unless valid_value?(val)
  val
end

#nameObject


15
16
17
# File 'lib/odata/types/primitive_types/int_16_type.rb', line 15

def name
  "Edm.Int16"
end

#valid_value?(value) ⇒ Boolean


3
4
5
6
7
# File 'lib/odata/types/primitive_types/int_16_type.rb', line 3

def valid_value?(value)
  Integer === value &&
    value <= 2**15 &&
    value > -(2**15)
end