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.
- #to_adoc ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Document
Returns a new instance of Document.
63 64 65 66 67 68 69 |
# File 'lib/coradoc/document.rb', line 63 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.
61 62 63 |
# File 'lib/coradoc/document.rb', line 61 def document_attributes @document_attributes end |
#header ⇒ Object
Returns the value of attribute header.
61 62 63 |
# File 'lib/coradoc/document.rb', line 61 def header @header end |
#sections ⇒ Object
Returns the value of attribute sections.
61 62 63 |
# File 'lib/coradoc/document.rb', line 61 def sections @sections end |
Class Method Details
.from_adoc(filename) ⇒ Object
32 33 34 35 |
# File 'lib/coradoc/document.rb', line 32 def from_adoc(filename) ast = Coradoc::Parser.parse(filename) Coradoc::Transformer.transform(ast) end |
.from_ast(elements) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/coradoc/document.rb', line 37 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 |