Class: Defmastership::Document

Inherits:
Object
  • Object
show all
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

Constructor Details

#initializeDocument

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

Parameters:

  • method_name (Symbol)

    the name of the method

  • args (Array<Object>)

    the arguments of the method



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.

Returns:

  • (Boolean)

    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

Parameters:

  • adoc_file (String)

    the file to parse



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.

Parameters:

  • reference (String)

    the defintion from the reference

Returns:

  • (Definition)

    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

Parameters:

  • method_name (Symbol)

    the name of the method

  • _args (Array<Object>)

    the arguments of the method

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)

    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