Class: ManyfoldApi::V0::ModelFileDeserializer

Inherits:
BaseDeserializer show all
Defined in:
app/deserializers/manyfold_api/v0/model_file_deserializer.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseDeserializer

#dereference, #initialize, schema_ref, schema_ref_name

Constructor Details

This class inherits a constructor from ManyfoldApi::V0::BaseDeserializer

Class Method Details

.schema ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/deserializers/manyfold_api/v0/model_file_deserializer.rb', line 17

def self.schema
  {
    type: :object,
    properties: {
      filename: {type: :string, example: "model.stl"},
      description: {type: :string, example: "Lorem ipsum dolor sit amet..."}, # rubocop:disable I18n/RailsI18n/DecorateString
      caption: {type: :string, example: "A short caption describing the file"},
      presupported: {type: :boolean, example: true},
      up: {type: :string, enum: ["+y", "+z"], example: "+y"},
      previewable: {type: :boolean, example: false},
      related: {
        type: :array,
        items: {
          type: :object,
          properties: {
            "@id": {type: :string, example: "https://example.com/models/abc123/model_files/def456"},
            "@type": {type: :string, example: "3DModel"},
            relationship: {type: :string, enum: ["presupported_version", "presupported_version_of"], example: "presupported_version"}
          }
        }
      }
    }
  }
end

Instance Method Details

#deserialize ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'app/deserializers/manyfold_api/v0/model_file_deserializer.rb', line 3

def deserialize
  return unless @object
  supported_version = dereference(@object["related"]&.find { it["relationship"] == "presupported_version" }&.dig("@id"), ModelFile)
  {
    filename: @object["filename"],
    notes: @object["description"],
    caption: @object["caption"],
    presupported: @object["presupported"],
    y_up: @object["up"] == "+y",
    previewable: @object["presupported"],
    presupported_version: supported_version
  }.compact
end