Class: Mindee::Input::DataSchema
- Inherits:
-
Object
- Object
- Mindee::Input::DataSchema
- Defined in:
- lib/mindee/input/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
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/mindee/input/data_schema.rb', line 95 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::Input::DataSchemaReplace (readonly)
92 93 94 |
# File 'lib/mindee/input/data_schema.rb', line 92 def replace @replace end |
Instance Method Details
#to_hash ⇒ Hash
116 117 118 |
# File 'lib/mindee/input/data_schema.rb', line 116 def to_hash { replace: @replace.to_hash } end |
#to_s ⇒ String
121 122 123 |
# File 'lib/mindee/input/data_schema.rb', line 121 def to_s to_hash.to_json end |