Class: Coradoc::Document

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Document

Returns a new instance of Document.



56
57
58
59
60
61
# File 'lib/coradoc/document.rb', line 56

def initialize(options={})
  @document_attributes = options.fetch(:document_attributes, Coradoc::Element::DocumentAttributes.new)
  @header = options.fetch(:header, Coradoc::Element::Header.new(""))
  @sections = options.fetch(:sections, [])
  self
end

Instance Attribute Details

#document_attributesObject

Returns the value of attribute document_attributes.



54
55
56
# File 'lib/coradoc/document.rb', line 54

def document_attributes
  @document_attributes
end

#headerObject

Returns the value of attribute header.



54
55
56
# File 'lib/coradoc/document.rb', line 54

def header
  @header
end

#sectionsObject

Returns the value of attribute sections.



54
55
56
# File 'lib/coradoc/document.rb', line 54

def sections
  @sections
end

Class Method Details

.from_adoc(filename) ⇒ Object



25
26
27
28
# File 'lib/coradoc/document.rb', line 25

def from_adoc(filename)
  ast = Coradoc::Parser.parse(filename)
  Coradoc::Transformer.transform(ast)
end

.from_ast(elements) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/coradoc/document.rb', line 30

def from_ast(elements)
  @sections = []

  elements.each do |element|
    case element
    when Coradoc::Element::DocumentAttributes
      @document_attributes = element

    when Coradoc::Element::Header
      @header = element

    when Coradoc::Element::Section
      @sections << element
    end
  end

  self.new(
    document_attributes: @document_attributes,
    header: @header,
    sections: @sections
  )
end