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: []) ⇒ Document

Returns a new instance of Document.



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

def initialize(metadata: {}, sections: [], preface: [], bibliography: [],
               cover: nil, style_id: :document, footnotes: [])
  @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
  freeze
end

Instance Attribute Details

#bibliographyObject (readonly)

Returns the value of attribute bibliography.



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

def bibliography
  @bibliography
end

#coverObject (readonly)

Returns the value of attribute cover.



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

def cover
  @cover
end

#footnotesObject (readonly)

Returns the value of attribute footnotes.



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

def footnotes
  @footnotes
end

#metadataObject (readonly)

Returns the value of attribute metadata.



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

def 
  @metadata
end

#prefaceObject (readonly)

Returns the value of attribute preface.



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

def preface
  @preface
end

#sectionsObject (readonly)

Returns the value of attribute sections.



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

def sections
  @sections
end

#style_idObject (readonly)

Returns the value of attribute style_id.



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

def style_id
  @style_id
end

Class Method Details

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



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

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

Instance Method Details

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



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

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



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

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

#editionObject



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

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

#hashObject



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

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

#titleObject



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

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