Class: DocumentExporter::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/document_exporter/base.rb

Direct Known Subclasses

Gdoc::Base, PDF::Base

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document, options = {}) ⇒ Base

Returns a new instance of Base.



9
10
11
12
# File 'lib/document_exporter/base.rb', line 9

def initialize(document, options = {})
  @document = document
  @options = options
end

Class Method Details

.pdf_key(type) ⇒ Object



5
6
7
# File 'lib/document_exporter/base.rb', line 5

def self.pdf_key(type)
  type == 'full' ? 'pdf' : "pdf_#{type}"
end

Instance Method Details

#exportObject

Raises:

  • (NotImplementedError)


14
15
16
# File 'lib/document_exporter/base.rb', line 14

def export
  raise NotImplementedError
end

#included_materials(context_type: :default) ⇒ Object

Take into consideration that in one component materilas are uniq. So just the first occurence of exluded material is removed



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/document_exporter/base.rb', line 22

def included_materials(context_type: :default)
  parts = context_type == :default ? @document.document_parts.default : @document.document_parts.gdoc

  @included_materials ||= [].tap do |result|
    # Take non optional materials ONLY
    result.concat parts.general.pluck(:materials).flatten.compact

    @options[:excludes]&.each do |x|
      next unless (part = parts.find_by anchor: x)

      # if it's optional activity - add it
      # otherwise - delete it from result
      part.materials.compact.each do |id|
        part.optional? ? result.push(id) : result.delete_at(result.index(id))
      end
    end
  end.map(&:to_i)
end

#ordered_materials(material_ids) ⇒ Object



41
42
43
# File 'lib/document_exporter/base.rb', line 41

def ordered_materials(material_ids)
  @document.ordered_material_ids & material_ids
end