Class: DefMastership::Document
- Inherits:
-
Object
- Object
- DefMastership::Document
- Defined in:
- lib/defmastership/document.rb
Overview
Reflects document structure from a definition point of view
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#definitions ⇒ Object
readonly
Returns the value of attribute definitions.
-
#eref ⇒ Object
readonly
Returns the value of attribute eref.
-
#iref ⇒ Object
readonly
Returns the value of attribute iref.
-
#labels ⇒ Object
readonly
Returns the value of attribute labels.
-
#variables ⇒ Object
readonly
Returns the value of attribute variables.
Instance Method Summary collapse
- #add_line(_match, line) ⇒ Object
- #add_new_definition(match, line) ⇒ Object
- #code_block_delimiter(_match, line) ⇒ Object
- #explicit_version? ⇒ Boolean
-
#initialize ⇒ Document
constructor
A new instance of Document.
- #new_attribute_conf(match, line) ⇒ Object
- #new_attribute_value(match, line) ⇒ Object
- #new_eref_def(match, line) ⇒ Object
- #new_eref_setup(match, line) ⇒ Object
- #new_iref_def(_match, line) ⇒ Object
- #new_variable_def(match, line) ⇒ Object
- #new_variable_use(_match, line) ⇒ Object
- #parse(lines) ⇒ Object
- #parse_file_with_preprocessor(adoc_file) ⇒ Object
- #ref_to_def(ref) ⇒ Object
- #wrong_explicit_checksum? ⇒ Boolean
Constructor Details
#initialize ⇒ Document
Returns a new instance of Document.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/defmastership/document.rb', line 13 def initialize @definitions = [] @labels = Set.new @eref = {} @iref = false @attributes = {} @in_literal = true @variables = {} @definition_parser = DefinitionParser.new(self) end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
11 12 13 |
# File 'lib/defmastership/document.rb', line 11 def attributes @attributes end |
#definitions ⇒ Object (readonly)
Returns the value of attribute definitions.
11 12 13 |
# File 'lib/defmastership/document.rb', line 11 def definitions @definitions end |
#eref ⇒ Object (readonly)
Returns the value of attribute eref.
11 12 13 |
# File 'lib/defmastership/document.rb', line 11 def eref @eref end |
#iref ⇒ Object (readonly)
Returns the value of attribute iref.
11 12 13 |
# File 'lib/defmastership/document.rb', line 11 def iref @iref end |
#labels ⇒ Object (readonly)
Returns the value of attribute labels.
11 12 13 |
# File 'lib/defmastership/document.rb', line 11 def labels @labels end |
#variables ⇒ Object (readonly)
Returns the value of attribute variables.
11 12 13 |
# File 'lib/defmastership/document.rb', line 11 def variables @variables end |
Instance Method Details
#add_line(_match, line) ⇒ Object
68 69 70 71 |
# File 'lib/defmastership/document.rb', line 68 def add_line(_match, line) @definitions.last << line line end |
#add_new_definition(match, line) ⇒ Object
57 58 59 60 61 62 |
# File 'lib/defmastership/document.rb', line 57 def add_new_definition(match, line) definition = Definition.new(match) @labels.merge(definition.labels) @definitions << definition line end |
#code_block_delimiter(_match, line) ⇒ Object
52 53 54 55 |
# File 'lib/defmastership/document.rb', line 52 def code_block_delimiter(_match, line) @in_literal ^= true line end |
#explicit_version? ⇒ Boolean
46 47 48 49 50 |
# File 'lib/defmastership/document.rb', line 46 def explicit_version? @definitions.reduce(false) do |res, definition| res || !definition.explicit_version.nil? end end |
#new_attribute_conf(match, line) ⇒ Object
92 93 94 95 |
# File 'lib/defmastership/document.rb', line 92 def new_attribute_conf(match, line) @attributes[match[:attr].to_sym] = match[:prefix] line end |
#new_attribute_value(match, line) ⇒ Object
97 98 99 100 |
# File 'lib/defmastership/document.rb', line 97 def new_attribute_value(match, line) @definitions.last.set_attribute(match[:attr].to_sym, match[:value]) line end |
#new_eref_def(match, line) ⇒ Object
79 80 81 82 |
# File 'lib/defmastership/document.rb', line 79 def new_eref_def(match, line) @definitions.last.add_eref(match[:refname].to_sym, match[:extrefs]) line end |
#new_eref_setup(match, line) ⇒ Object
73 74 75 76 77 |
# File 'lib/defmastership/document.rb', line 73 def new_eref_setup(match, line) @eref[match[:refname].to_sym] ||= {} @eref[match[:refname].to_sym][match[:symb].to_sym] = match[:value] line end |
#new_iref_def(_match, line) ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/defmastership/document.rb', line 84 def new_iref_def(_match, line) @iref = true line.scan(DMRegexp::IREF_DEF) do |_| @definitions.last.add_iref(Regexp.last_match[:intref]) end line end |
#new_variable_def(match, line) ⇒ Object
102 103 104 105 |
# File 'lib/defmastership/document.rb', line 102 def new_variable_def(match, line) @variables[match[:varname].to_sym] = match[:value] line end |
#new_variable_use(_match, line) ⇒ Object
107 108 109 110 111 112 113 114 115 |
# File 'lib/defmastership/document.rb', line 107 def new_variable_use(_match, line) line.scan(DMRegexp::VARIABLE_USE) do |_| varname = Regexp.last_match[:varname] next if @variables[varname.to_sym].nil? line = line.gsub("{#{varname}}", @variables[varname.to_sym]) end line end |
#parse(lines) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/defmastership/document.rb', line 24 def parse(lines) lines.reject(&:commented?).each do |line| (@in_literal ? FILTERS : FILTERS_IN_LITERAL).each do |filter| next unless line.match(filter.regexp) line = generate_event(filter.event, Regexp.last_match, line) break if filter.consumed_line end end end |
#parse_file_with_preprocessor(adoc_file) ⇒ Object
36 37 38 |
# File 'lib/defmastership/document.rb', line 36 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
64 65 66 |
# File 'lib/defmastership/document.rb', line 64 def ref_to_def(ref) @definitions.find { |definition| definition.reference == ref } end |
#wrong_explicit_checksum? ⇒ Boolean
40 41 42 43 44 |
# File 'lib/defmastership/document.rb', line 40 def wrong_explicit_checksum? @definitions.reduce(false) do |res, definition| res || !definition.wrong_explicit_checksum.nil? end end |