Class: Coradoc::Document
- Inherits:
-
Object
- Object
- Coradoc::Document
- Defined in:
- lib/coradoc/document.rb
Instance Attribute Summary collapse
-
#document_attributes ⇒ Object
Returns the value of attribute document_attributes.
-
#header ⇒ Object
Returns the value of attribute header.
-
#sections ⇒ Object
Returns the value of attribute sections.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Document
constructor
A new instance of Document.
Constructor Details
#initialize(options = {}) ⇒ Document
Returns a new instance of Document.
56 57 58 59 60 61 62 |
# File 'lib/coradoc/document.rb', line 56 def initialize( = {}) @document_attributes = .fetch(:document_attributes, Coradoc::Element::DocumentAttributes.new) @header = .fetch(:header, Coradoc::Element::Header.new("")) @sections = .fetch(:sections, []) self end |
Instance Attribute Details
#document_attributes ⇒ Object
Returns the value of attribute document_attributes.
54 55 56 |
# File 'lib/coradoc/document.rb', line 54 def document_attributes @document_attributes end |
#header ⇒ Object
Returns the value of attribute header.
54 55 56 |
# File 'lib/coradoc/document.rb', line 54 def header @header end |
#sections ⇒ Object
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 new( document_attributes: @document_attributes, header: @header, sections: @sections, ) end |