Class: Mindee::Input::DataSchemaReplace

Inherits:
Object
  • Object
show all
Defined in:
lib/mindee/input/data_schema.rb

Overview

The structure to completely replace the data schema of the model.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data_schema_replace) ⇒ DataSchemaReplace

Returns a new instance of DataSchemaReplace.

Parameters:

  • data_schema_replace (Hash)

Raises:



69
70
71
72
73
74
75
76
# File 'lib/mindee/input/data_schema.rb', line 69

def initialize(data_schema_replace)
  data_schema_replace.transform_keys!(&:to_sym)
  fields_list = data_schema_replace[:fields]
  raise Mindee::Errors::MindeeError, 'Invalid Data Schema provided.' if fields_list.nil?
  raise TypeError, 'Data Schema replacement fields cannot be empty.' if fields_list.empty?

  @fields = fields_list.map { |field| DataSchemaField.new(field) }
end

Instance Attribute Details

#fieldsArray<DataSchemaField> (readonly)

Returns Subfields when type is nested_object. Leave empty for other types.

Returns:

  • (Array<DataSchemaField>)

    Subfields when type is nested_object. Leave empty for other types.



66
67
68
# File 'lib/mindee/input/data_schema.rb', line 66

def fields
  @fields
end

Instance Method Details

#to_hashHash

Returns:

  • (Hash)


79
80
81
# File 'lib/mindee/input/data_schema.rb', line 79

def to_hash
  { fields: @fields.map(&:to_hash) }
end

#to_sString

Returns:

  • (String)


84
85
86
# File 'lib/mindee/input/data_schema.rb', line 84

def to_s
  to_hash.to_json
end