Class: DocTemplate::Objects::MaterialMetadata

Inherits:
Object
  • Object
show all
Defined in:
lib/doc_template/objects/material_metadata.rb

Constant Summary collapse

KEY_PARAMS =
%w(breadcrumb_level sheet_type type).freeze

Class Method Summary collapse

Class Method Details

.build_from(data) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/doc_template/objects/material_metadata.rb', line 31

def build_from(data)
  materials_data = data.transform_keys { |k| k.to_s.underscore }
                     .delete_if { |_, v| v&.strip.blank? }
  KEY_PARAMS.each do |k|
    materials_data[k] = materials_data[k].to_s.downcase if materials_data.key?(k)
  end

  new(materials_data)
end

.build_from_pdf(identifier:, title:) ⇒ Object



41
42
43
# File 'lib/doc_template/objects/material_metadata.rb', line 41

def build_from_pdf(identifier:, title:)
  new(identifier: identifier, sheet_type: 'pdf', title: title, type: 'pdf')
end

.dump(data) ⇒ Object



45
46
47
# File 'lib/doc_template/objects/material_metadata.rb', line 45

def dump(data)
  data.as_json
end

.load(data) ⇒ Object



49
50
51
# File 'lib/doc_template/objects/material_metadata.rb', line 49

def load(data)
  new(data)
end