Class: Lcms::Engine::Material
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Partable
#create_parts_for, #layout
Class Method Details
28
29
30
31
|
# File 'app/models/lcms/engine/material.rb', line 28
def self.where_metadata_any_of(conditions)
condition = Array.new(conditions.size, 'materials.metadata @> ?').join(' or ')
where(condition, *conditions.map(&:to_json))
end
|
Instance Method Details
#file_url ⇒ Object
33
34
35
|
# File 'app/models/lcms/engine/material.rb', line 33
def file_url
"https://docs.google.com/#{pdf? ? 'file' : 'document'}/d/#{file_id}"
end
|
#optional_for?(document) ⇒ Boolean
Material is optional if it’s included in optional activity only
38
39
40
41
42
43
|
# File 'app/models/lcms/engine/material.rb', line 38
def optional_for?(document)
general_ids = document.document_parts.general.pluck(:materials).flatten
optional_ids = document.document_parts.optional.pluck(:materials).flatten
optional_ids.include?(id.to_s) && general_ids.exclude?(id.to_s)
end
|
#pdf? ⇒ Boolean
45
46
47
|
# File 'app/models/lcms/engine/material.rb', line 45
def pdf?
metadata['type'].to_s.casecmp('pdf').zero?
end
|
#source_type ⇒ Object
49
50
51
|
# File 'app/models/lcms/engine/material.rb', line 49
def source_type
pdf? ? 'pdf' : 'gdoc'
end
|