Class: Mindee::V2::Product::Extraction::Params::DataSchema
- Inherits:
-
Object
- Object
- Mindee::V2::Product::Extraction::Params::DataSchema
- Defined in:
- lib/mindee/v2/product/extraction/params/data_schema.rb
Overview
Modify the Data Schema.
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#initialize(data_schema) ⇒ DataSchema
constructor
A new instance of DataSchema.
- #to_hash ⇒ Hash
- #to_s ⇒ String
Constructor Details
#initialize(data_schema) ⇒ DataSchema
Returns a new instance of DataSchema.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/mindee/v2/product/extraction/params/data_schema.rb', line 17 def initialize(data_schema) case data_schema when String parsed = JSON.parse(data_schema.to_s, object_class: Hash) parsed.transform_keys!(&:to_sym) @replace = DataSchemaReplace.new(parsed[:replace]) when Hash data_schema.transform_keys!(&:to_sym) @replace = if data_schema[:replace].is_a?(DataSchemaReplace) data_schema[:replace] else DataSchemaReplace.new(data_schema[:replace]) end when DataSchema @replace = data_schema.replace else raise TypeError, 'Invalid Data Schema provided.' end end |
Instance Attribute Details
#replace ⇒ Mindee::V2::Product::Extraction::Params::DataSchemaReplace (readonly)
14 15 16 |
# File 'lib/mindee/v2/product/extraction/params/data_schema.rb', line 14 def replace @replace end |
Instance Method Details
#to_hash ⇒ Hash
38 39 40 |
# File 'lib/mindee/v2/product/extraction/params/data_schema.rb', line 38 def to_hash { replace: @replace.to_hash } end |
#to_s ⇒ String
43 44 45 |
# File 'lib/mindee/v2/product/extraction/params/data_schema.rb', line 43 def to_s to_hash.to_json end |