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

Instance Method Summary collapse

Constructor Details

#initializeDocument

Returns a new instance of Document.



85
86
87
88
89
# File 'lib/defmastership/document.rb', line 85

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



123
124
125
126
127
128
# File 'lib/defmastership/document.rb', line 123

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



113
114
115
116
117
# File 'lib/defmastership/document.rb', line 113

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



94
95
96
# File 'lib/defmastership/document.rb', line 94

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



141
142
143
# File 'lib/defmastership/document.rb', line 141

def ref_to_def(reference)
  definitions.find { |definition| definition.reference.eql?(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)


135
136
137
# File 'lib/defmastership/document.rb', line 135

def respond_to_missing?(method_name, *_args)
  PARSER_ACTIONS.key?(method_name)
end

#summaries?Boolean

Returns true if the document has definitions with summary.

Returns:

  • (Boolean)

    true if the document has definitions with summary



99
100
101
102
103
# File 'lib/defmastership/document.rb', line 99

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.

Returns:

  • (Boolean)

    true if the document has definitions with wrong explicit checksum



106
107
108
109
110
# File 'lib/defmastership/document.rb', line 106

def wrong_explicit_checksum?
  definitions.reduce(false) do |res, definition|
    res || !!definition.wrong_explicit_checksum
  end
end