Class: Arrolio::Content::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/arrolio/content/document.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(metadata: {}, sections: [], preface: [], bibliography: [], cover: nil, style_id: :document, footnotes: [], title_block: nil) ⇒ Document

Returns a new instance of Document.



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/arrolio/content/document.rb', line 14

def initialize(metadata: {}, sections: [], preface: [], bibliography: [],
               cover: nil, style_id: :document, footnotes: [],
               title_block: nil)
  @metadata = .to_h.freeze
  @sections = validate_sections(Array(sections), field: :sections).freeze
  @preface = validate_sections(Array(preface), field: :preface).freeze
  @bibliography = validate_sections(Array(bibliography), field: :bibliography).freeze
  @cover = cover
  @style_id = style_id.to_sym
  @footnotes = Array(footnotes).freeze
  @title_block = title_block
  freeze
end

Instance Attribute Details

#bibliographyObject (readonly)

Returns the value of attribute bibliography.



7
8
9
# File 'lib/arrolio/content/document.rb', line 7

def bibliography
  @bibliography
end

#coverObject (readonly)

Returns the value of attribute cover.



7
8
9
# File 'lib/arrolio/content/document.rb', line 7

def cover
  @cover
end

#footnotesObject (readonly)

Returns the value of attribute footnotes.



7
8
9
# File 'lib/arrolio/content/document.rb', line 7

def footnotes
  @footnotes
end

#metadataObject (readonly)

Returns the value of attribute metadata.



7
8
9
# File 'lib/arrolio/content/document.rb', line 7

def 
  @metadata
end

#prefaceObject (readonly)

Returns the value of attribute preface.



7
8
9
# File 'lib/arrolio/content/document.rb', line 7

def preface
  @preface
end

#sectionsObject (readonly)

Returns the value of attribute sections.



7
8
9
# File 'lib/arrolio/content/document.rb', line 7

def sections
  @sections
end

#style_idObject (readonly)

Returns the value of attribute style_id.



7
8
9
# File 'lib/arrolio/content/document.rb', line 7

def style_id
  @style_id
end

#title_blockObject (readonly)

Returns the value of attribute title_block.



7
8
9
# File 'lib/arrolio/content/document.rb', line 7

def title_block
  @title_block
end

Class Method Details

.build(metadata: {}, **opts, &block) ⇒ Object



10
11
12
# File 'lib/arrolio/content/document.rb', line 10

def self.build(metadata: {}, **opts, &block)
  Builder.build(metadata: , **opts, &block)
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



32
33
34
35
36
37
38
# File 'lib/arrolio/content/document.rb', line 32

def ==(other)
  other.is_a?(self.class) &&
     == other. && sections == other.sections &&
    preface == other.preface && bibliography == other.bibliography &&
    cover == other.cover && style_id == other.style_id &&
    footnotes == other.footnotes
end

#docidentifierObject



29
# File 'lib/arrolio/content/document.rb', line 29

def docidentifier = @metadata[:docidentifier] || @metadata['docidentifier']

#editionObject



30
# File 'lib/arrolio/content/document.rb', line 30

def edition = @metadata[:edition] || @metadata['edition']

#hashObject



41
42
43
44
# File 'lib/arrolio/content/document.rb', line 41

def hash
  [self.class, , sections, preface, bibliography, cover,
   style_id, footnotes].hash
end

#titleObject



28
# File 'lib/arrolio/content/document.rb', line 28

def title = @metadata[:title] || @metadata['title']