Class: Defmastership::Document
- Inherits:
-
Object
- Object
- Defmastership::Document
- Extended by:
- Forwardable
- Defined in:
- lib/defmastership/document.rb
Overview
Reflects document structure from a definition point of view
Instance Method Summary collapse
-
#explicit_version? ⇒ Boolean
True if the document has definitions with explicit versions.
-
#initialize ⇒ Document
constructor
A new instance of Document.
-
#method_missing(method_name, *args) ⇒ Object
Allow to add methods from parser actions.
-
#parse_file_with_preprocessor(adoc_file) ⇒ Object
Parse asciidoc file after [Asciidoctor] preprocessing.
-
#ref_to_def(reference) ⇒ Definition
The defintion from the reference.
-
#respond_to_missing?(method_name, *_args) ⇒ Boolean
Allow to check if a parser action is available.
-
#summaries? ⇒ Boolean
True if the document has definitions with summary.
-
#wrong_explicit_checksum? ⇒ Boolean
True if the document has definitions with wrong explicit checksum.
Constructor Details
#initialize ⇒ Document
Returns a new instance of Document.
80 81 82 83 84 |
# File 'lib/defmastership/document.rb', line 80 def initialize @data = DocumentData.new([], Set.new, {}, false, {}, {}) @parsing_state = Core::ParsingState.new @definition_parser = DefinitionParser.new(self) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
Allow to add methods from parser actions
118 119 120 121 122 123 |
# File 'lib/defmastership/document.rb', line 118 def method_missing(method_name, *args) action = PARSER_ACTIONS[method_name] return instance_exec(*args, &action) if action super end |
Instance Method Details
#explicit_version? ⇒ Boolean
Returns true if the document has definitions with explicit versions.
108 109 110 111 112 |
# File 'lib/defmastership/document.rb', line 108 def explicit_version? definitions.reduce(false) do |res, definition| res || !!definition.explicit_version end end |
#parse_file_with_preprocessor(adoc_file) ⇒ Object
Parse asciidoc file after [Asciidoctor] preprocessing
89 90 91 |
# File 'lib/defmastership/document.rb', line 89 def parse_file_with_preprocessor(adoc_file) do_parse(Asciidoctor.load_file(adoc_file, safe: :unsafe, parse: false).reader.read_lines) end |
#ref_to_def(reference) ⇒ Definition
Returns the defintion from the reference.
136 137 138 |
# File 'lib/defmastership/document.rb', line 136 def ref_to_def(reference) definitions.find { |definition| definition.reference == reference } end |
#respond_to_missing?(method_name, *_args) ⇒ Boolean
Allow to check if a parser action is available
This method smells of :reek:UtilityFunction
130 131 132 |
# File 'lib/defmastership/document.rb', line 130 def respond_to_missing?(method_name, *_args) PARSER_ACTIONS.key?(method_name) end |
#summaries? ⇒ Boolean
Returns true if the document has definitions with summary.
94 95 96 97 98 |
# File 'lib/defmastership/document.rb', line 94 def summaries? definitions.reduce(false) do |res, definition| res || !!definition.summary end end |
#wrong_explicit_checksum? ⇒ Boolean
Returns true if the document has definitions with wrong explicit checksum.
101 102 103 104 105 |
# File 'lib/defmastership/document.rb', line 101 def wrong_explicit_checksum? definitions.reduce(false) do |res, definition| res || !!definition.wrong_explicit_checksum end end |