Class: Mindee::Input::DataSchemaReplace
- Inherits:
-
Object
- Object
- Mindee::Input::DataSchemaReplace
- Defined in:
- lib/mindee/input/data_schema.rb
Overview
The structure to completely replace the data schema of the model.
Instance Attribute Summary collapse
-
#fields ⇒ Array<DataSchemaField>
readonly
Subfields when type is
nested_object.
Instance Method Summary collapse
-
#initialize(data_schema_replace) ⇒ DataSchemaReplace
constructor
A new instance of DataSchemaReplace.
- #to_hash ⇒ Hash
- #to_s ⇒ String
Constructor Details
#initialize(data_schema_replace) ⇒ DataSchemaReplace
Returns a new instance of DataSchemaReplace.
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
#fields ⇒ Array<DataSchemaField> (readonly)
Returns 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_hash ⇒ Hash
79 80 81 |
# File 'lib/mindee/input/data_schema.rb', line 79 def to_hash { fields: @fields.map(&:to_hash) } end |
#to_s ⇒ String
84 85 86 |
# File 'lib/mindee/input/data_schema.rb', line 84 def to_s to_hash.to_json end |