Class: OdataDuty::EdmBool

Inherits:
EdmBase
  • Object
show all
Defined in:
lib/odata_duty/edms.rb

Constant Summary collapse

OAS_TYPE =
{ 'type' => 'boolean' }.freeze
VALID_VALUES =
[true, false, nil].freeze

Class Method Summary collapse

Methods inherited from EdmBase

scalar?

Class Method Details

.property_typeObject



91
92
93
# File 'lib/odata_duty/edms.rb', line 91

def self.property_type
  'Edm.Boolean'
end

.to_oas2(is_collection:) ⇒ Object



97
98
99
100
101
# File 'lib/odata_duty/edms.rb', line 97

def self.to_oas2(is_collection:)
  return { 'type' => 'array', 'items' => OAS_TYPE } if is_collection

  OAS_TYPE
end

.to_value(object, _context) ⇒ Object



105
106
107
108
109
110
111
112
113
# File 'lib/odata_duty/edms.rb', line 105

def self.to_value(object, _context)
  return true if object == 'true'
  return false if object == 'false'
  return object if VALID_VALUES.include?(object)

  object.to_boolean
rescue NoMethodError
  raise InvalidValue, "#{object} not boolean value"
end