Class: DocTemplate::Objects::MaterialMetadata
- Inherits:
-
Object
- Object
- DocTemplate::Objects::MaterialMetadata
- 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
- .build_from(data) ⇒ Object
- .build_from_pdf(identifier:, title:) ⇒ Object
- .dump(data) ⇒ Object
- .load(data) ⇒ Object
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 |