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.



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

def initialize
  @data = DocumentData.new([], Set.new, {}, false, {}, {})
  @parsing_state = 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



116
117
118
119
120
121
# File 'lib/defmastership/document.rb', line 116

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:

  • (Boolean)


110
111
112
113
114
# File 'lib/defmastership/document.rb', line 110

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

#iref=(value) ⇒ Object



132
133
134
# File 'lib/defmastership/document.rb', line 132

def iref=(value)
  @data.iref = value
end

#parse(lines) ⇒ Object



90
91
92
93
94
95
96
97
98
# File 'lib/defmastership/document.rb', line 90

def parse(lines)
  lines.each do |line|
    if @parsing_state.enabled?(line)
      apply_filters(line)
    else
      generate_event(:new_line, MatchingLine.new(nil, line))
    end
  end
end

#parse_file_with_preprocessor(adoc_file) ⇒ Object



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

def parse_file_with_preprocessor(adoc_file)
  parse(Asciidoctor.load_file(adoc_file, safe: :unsafe, parse: false).reader.read_lines)
end

#ref_to_def(ref) ⇒ Object



128
129
130
# File 'lib/defmastership/document.rb', line 128

def ref_to_def(ref)
  definitions.find { |definition| definition.reference == ref }
end

#respond_to_missing?(method_name, *_args) ⇒ Boolean

This method smells of :reek:UtilityFunction

Returns:

  • (Boolean)


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

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

#wrong_explicit_checksum?Boolean

Returns:

  • (Boolean)


104
105
106
107
108
# File 'lib/defmastership/document.rb', line 104

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