Class: OmniAI::Schema::Scalar
- Inherits:
-
Object
- Object
- OmniAI::Schema::Scalar
- Defined in:
- lib/omniai/schema/scalar.rb
Overview
Defined Under Namespace
Modules: Type
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
- #initialize(type:, description: nil, enum: nil) ⇒ OmniAI::Schema::Scalar constructor
- #parse(value) ⇒ String, ...
- #serialize ⇒ Hash
Constructor Details
#initialize(type:, description: nil, enum: nil) ⇒ OmniAI::Schema::Scalar
83 84 85 86 87 88 |
# File 'lib/omniai/schema/scalar.rb', line 83 def initialize(type:, description: nil, enum: nil) super() @type = type @description = description @enum = enum end |
Instance Attribute Details
#description ⇒ String?
39 40 41 |
# File 'lib/omniai/schema/scalar.rb', line 39 def description @description end |
#type ⇒ String
35 36 37 |
# File 'lib/omniai/schema/scalar.rb', line 35 def type @type end |
Class Method Details
.deserialize(data) ⇒ OmniAI::Schema::Scalar
70 71 72 73 74 75 76 |
# File 'lib/omniai/schema/scalar.rb', line 70 def self.deserialize(data) type = data["type"] || data[:type] || Type::STRING description = data["description"] || data[:description] enum = data["enum"] || data[:enum] new(type:, description:, enum:) end |
Instance Method Details
#parse(value) ⇒ String, ...
108 109 110 111 112 113 114 115 |
# File 'lib/omniai/schema/scalar.rb', line 108 def parse(value) case @type when Type::INTEGER then Integer(value) when Type::STRING then String(value) when Type::NUMBER then Float(value) else value end end |
#serialize ⇒ Hash
94 95 96 97 98 99 100 |
# File 'lib/omniai/schema/scalar.rb', line 94 def serialize { type: @type, description: @description, enum: @enum, }.compact end |