Module: Kwalify::Types

Included in:
Kwalify
Defined in:
lib/kwalify/types.rb

Constant Summary collapse

DEFAULT_TYPE =

use β€œstr” as default of @type

"str"
@@type_table =
{
  "seq"     => Array,
  "map"     => Hash,
  "str"     => String,
  #"string"   => String,
  "text"    => Text,
  "int"     => Integer,
  #"integer"  => Integer,
  "float"    => Float,
  "number"   => Numeric,
  #"numeric"  => Numeric,
  "date"    => Date,
  "time"    => Time,
  "timestamp" => Time,
  "bool"    => Boolean,
  #"boolean"  => Boolean,
  #"object"   => Object,
  "any"     => Object,
  "scalar"   => Scalar,
}

Class Method Summary collapse

Class Method Details

.collection?(val) ⇒ Boolean

– def collection_class?(klass)

return klass.is_a?(Array) || klass.is_a?(Hash)

end

def scalar_class?(klass)

return !klass.is_a?(Array) && !klass.is_a?(Hash) && klass != Object

end

Returns:



134
135
136
# File 'lib/kwalify/types.rb', line 134

def collection?(val)
  return val.is_a?(Array) || val.is_a?(Hash)
end

.collection_type?(type) ⇒ Boolean

Returns:



143
144
145
# File 'lib/kwalify/types.rb', line 143

def collection_type?(type)
  return type == 'seq' || type == 'map'
end

.get_type_class(type) ⇒ Object



119
120
121
# File 'lib/kwalify/types.rb', line 119

def self.get_type_class(type)
  return type_class(type)
end

.scalar?(val) ⇒ Boolean

Returns:



138
139
140
141
# File 'lib/kwalify/types.rb', line 138

def scalar?(val)
  #return !val.is_a?(Array) && !val.is_a?(Hash) && val.class != Object
  return val.is_a?(Kwalify::Scalar)  #&& val.class != Object
end

.scalar_type?(type) ⇒ Boolean

Returns:



147
148
149
# File 'lib/kwalify/types.rb', line 147

def scalar_type?(type)
  return type != 'seq' && type != 'map' && type == 'any'
end

.type_class(type) ⇒ Object



113
114
115
116
117
# File 'lib/kwalify/types.rb', line 113

def self.type_class(type)
  klass = @@type_table[type]
  #assert_error('type=#{type.inspect}') unless klass
  return klass
end

.type_tableObject



109
110
111
# File 'lib/kwalify/types.rb', line 109

def self.type_table
  return @@type_table
end