Class: Mindee::V2::Product::Extraction::Params::DataSchema

Inherits:
Object
  • Object
show all
Defined in:
lib/mindee/v2/product/extraction/params/data_schema.rb

Overview

Modify the Data Schema.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data_schema) ⇒ DataSchema

Returns a new instance of DataSchema.

Parameters:

  • data_schema (Hash, String)


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

#replaceMindee::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_hashHash

Returns:

  • (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_sString

Returns:

  • (String)


43
44
45
# File 'lib/mindee/v2/product/extraction/params/data_schema.rb', line 43

def to_s
  to_hash.to_json
end