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
Defined Under Namespace
Modules: Helper
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.
-
#wrong_explicit_checksum? ⇒ Boolean
True if the document has definitions with wrong explicit checksum.
Constructor Details
#initialize ⇒ Document
Returns a new instance of Document.
78 79 80 81 82 |
# File 'lib/defmastership/document.rb', line 78 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
109 110 111 112 113 114 |
# File 'lib/defmastership/document.rb', line 109 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.
99 100 101 102 103 |
# File 'lib/defmastership/document.rb', line 99 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
87 88 89 |
# File 'lib/defmastership/document.rb', line 87 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.
127 128 129 |
# File 'lib/defmastership/document.rb', line 127 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
121 122 123 |
# File 'lib/defmastership/document.rb', line 121 def respond_to_missing?(method_name, *_args) PARSER_ACTIONS.key?(method_name) end |
#wrong_explicit_checksum? ⇒ Boolean
Returns true if the document has definitions with wrong explicit checksum.
92 93 94 95 96 |
# File 'lib/defmastership/document.rb', line 92 def wrong_explicit_checksum? definitions.reduce(false) do |res, definition| res || !!definition.wrong_explicit_checksum end end |