Module: Kumi::Core::Types
- Defined in:
- lib/kumi/core/types.rb,
lib/kumi/core/types/inference.rb,
lib/kumi/core/types/validator.rb,
lib/kumi/core/types/normalizer.rb,
lib/kumi/core/types/value_objects.rb
Defined Under Namespace
Modules: ValueObjects Classes: ArrayType, Inference, Normalizer, ScalarType, TupleType, Type, Validator
Constant Summary collapse
- VALID_TYPES =
Re-export constants for compatibility
Validator::VALID_TYPES
Class Method Summary collapse
- .array(element_type) ⇒ Object
- .array?(dtype) ⇒ Boolean
- .collection?(dtype) ⇒ Boolean
- .hash(key_type, val_type) ⇒ Object
-
.infer_from_value(value) ⇒ Object
Type inference.
-
.normalize(type_input) ⇒ Object
Normalization.
-
.scalar(kind) ⇒ Object
Type value object constructors.
- .tuple(element_types) ⇒ Object
- .tuple?(dtype) ⇒ Boolean
-
.valid_type?(type) ⇒ Boolean
Validation methods.
Class Method Details
.array(element_type) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/kumi/core/types.rb', line 33 def self.array(element_type) elem_obj = case element_type when Type element_type when :string, :integer, :float, :decimal, :boolean, :hash, :any, :symbol, :regexp, :time, :date, :datetime, :null scalar(element_type) else raise ArgumentError, "array element must be Type object or scalar kind, got #{element_type.inspect}" end ArrayType.new(elem_obj) end |
.array?(dtype) ⇒ Boolean
19 20 21 |
# File 'lib/kumi/core/types.rb', line 19 def self.array?(dtype) dtype.is_a?(ArrayType) end |
.collection?(dtype) ⇒ Boolean
11 12 13 |
# File 'lib/kumi/core/types.rb', line 11 def self.collection?(dtype) tuple?(dtype) || array?(dtype) end |
.hash(key_type, val_type) ⇒ Object
64 65 66 |
# File 'lib/kumi/core/types.rb', line 64 def self.hash(key_type, val_type) raise NotImplementedError, "Use scalar(:hash) instead - Kumi treats hash as scalar, not key/value pair" end |
.infer_from_value(value) ⇒ Object
Type inference
74 75 76 |
# File 'lib/kumi/core/types.rb', line 74 def self.infer_from_value(value) Inference.infer_from_value(value) end |
.normalize(type_input) ⇒ Object
Normalization
69 70 71 |
# File 'lib/kumi/core/types.rb', line 69 def self.normalize(type_input) Normalizer.normalize(type_input) end |
.scalar(kind) ⇒ Object
Type value object constructors
29 30 31 |
# File 'lib/kumi/core/types.rb', line 29 def self.scalar(kind) ScalarType.new(kind) end |
.tuple(element_types) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/kumi/core/types.rb', line 46 def self.tuple(element_types) raise ArgumentError, "tuple expects array of Type objects, got #{element_types.class}" unless element_types.is_a?(Array) # Convert any non-Type elements to Type objects converted = element_types.map do |t| case t when Type t when :string, :integer, :float, :decimal, :boolean, :hash, :any, :symbol, :regexp, :time, :date, :datetime, :null scalar(t) else raise ArgumentError, "tuple element must be Type or scalar kind, got #{t.inspect}" end end TupleType.new(converted) end |
.tuple?(dtype) ⇒ Boolean
15 16 17 |
# File 'lib/kumi/core/types.rb', line 15 def self.tuple?(dtype) dtype.is_a?(TupleType) end |
.valid_type?(type) ⇒ Boolean
Validation methods
24 25 26 |
# File 'lib/kumi/core/types.rb', line 24 def self.valid_type?(type) Validator.valid_type?(type) end |