Class: Lcms::Engine::Material

Inherits:
ApplicationRecord show all
Includes:
Partable, PgSearch::Model
Defined in:
app/models/lcms/engine/material.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Partable

#create_parts_for, #layout

Class Method Details

.where_metadata_any_of(conditions) ⇒ Object



28
29
30
31
# File 'app/models/lcms/engine/material.rb', line 28

def self.(conditions)
  condition = Array.new(conditions.size, 'materials.metadata @> ?').join(' or ')
  where(condition, *conditions.map(&:to_json))
end

Instance Method Details

#file_urlObject



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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


45
46
47
# File 'app/models/lcms/engine/material.rb', line 45

def pdf?
  ['type'].to_s.casecmp('pdf').zero?
end

#source_typeObject



49
50
51
# File 'app/models/lcms/engine/material.rb', line 49

def source_type
  pdf? ? 'pdf' : 'gdoc'
end