Module: Scjson::Types::BooleanDatatypeProps

Defined in:
lib/scjson/types.rb

Overview

Boolean: true or false only

Constant Summary collapse

TRUE =
'true'.freeze
FALSE =
'false'.freeze
DEFAULT =
TRUE
VALUES =
[TRUE, FALSE].freeze

Class Method Summary collapse

Class Method Details

.coerce(value, allow_nil: false) ⇒ String?

Coerce arbitrary input into a valid enumeration value.

Parameters:

  • value (Object, nil)

    Raw value to coerce.

  • allow_nil (Boolean) (defaults to: false)

    When true, allow nil to pass-through.

Returns:

  • (String, nil)

Raises:

  • (ArgumentError)


111
112
113
114
115
116
117
118
119
# File 'lib/scjson/types.rb', line 111

def coerce(value, allow_nil: false)
  return nil if allow_nil && value.nil?
  return DEFAULT if value.nil?

  candidate = value.to_s
  return candidate if VALUES.include?(candidate)

  raise ArgumentError, "Unsupported value '#{value}' for BooleanDatatypeProps"
end

.defaultString

Returns Schema-defined default enumeration value.

Returns:

  • (String)

    Schema-defined default enumeration value.



103
104
105
# File 'lib/scjson/types.rb', line 103

def default
  DEFAULT
end

.valuesArray<String>

Returns All legal enumeration values.

Returns:

  • (Array<String>)

    All legal enumeration values.



98
99
100
# File 'lib/scjson/types.rb', line 98

def values
  VALUES
end