Class: Defmastership::Modifier::UpdateDef Abstract
- Inherits:
-
Object
- Object
- Defmastership::Modifier::UpdateDef
- Includes:
- ModifierCommon
- Defined in:
- lib/defmastership/modifier/update_def.rb
Overview
Subclass and define reference_replacement
to implement a
custom reference replacement class
Direct Known Subclasses
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
Returns the value of attribute document.
Attributes included from ModifierCommon
Class Method Summary collapse
-
.default_config ⇒ Hash{Symbol => Object}
The default configuration.
-
.reference_regexp(reference) ⇒ Regexp
Builds a Regexp to match a particular reference defintion (with its optional version and checksum).
-
.replacement_methods ⇒ Array<Symbol>
The methods’s symbols that will be called in sequence for modifications.
Instance Method Summary collapse
-
#do_modifications(adoc_sources) ⇒ Object
Apply the modifier on all provided asciidoc sources based on modifier’s
self.replacement_methods
list. -
#initialize(config) ⇒ UpdateDef
constructor
A new instance of UpdateDef.
-
#replace_reference(line) ⇒ String
Called on each line for an opportunity for text replacement.
Methods included from ModifierCommon
#method_missing, #respond_to_missing?, #setup_modifier_module
Constructor Details
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Defmastership::Modifier::ModifierCommon
Instance Attribute Details
#document ⇒ Object (readonly)
Returns the value of attribute document.
13 14 15 |
# File 'lib/defmastership/modifier/update_def.rb', line 13 def document @document end |
Class Method Details
.default_config ⇒ Hash{Symbol => Object}
Returns the default configuration.
16 17 18 19 20 |
# File 'lib/defmastership/modifier/update_def.rb', line 16 def self.default_config { def_type: '' } end |
.reference_regexp(reference) ⇒ Regexp
Builds a Regexp to match a particular reference defintion (with its optional version and checksum)
32 33 34 |
# File 'lib/defmastership/modifier/update_def.rb', line 32 def self.reference_regexp(reference) Regexp.new("#{reference}#{Core::DMRegexp::DEF_VERSION_AND_CHECKSUM}") end |
.replacement_methods ⇒ Array<Symbol>
Returns the methods’s symbols that will be called in sequence for modifications.
23 24 25 |
# File 'lib/defmastership/modifier/update_def.rb', line 23 def self.replacement_methods %i[replace_reference] end |
Instance Method Details
#do_modifications(adoc_sources) ⇒ Object
Apply the modifier on all provided asciidoc sources based on modifier’s self.replacement_methods
list
49 50 51 52 53 54 55 |
# File 'lib/defmastership/modifier/update_def.rb', line 49 def do_modifications(adoc_sources) adoc_sources.each_key do |adoc_file| document.parse_file_with_preprocessor(adoc_file) end super end |
#replace_reference(line) ⇒ String
Called on each line for an opportunity for text replacement
61 62 63 64 65 66 67 68 69 |
# File 'lib/defmastership/modifier/update_def.rb', line 61 def replace_reference(line) match = line.match(Core::DMRegexp::DEFINITION) return line unless match return line unless match[:type] == def_type reference = match[:reference] line.sub(self.class.reference_regexp(reference), reference_replacement(reference, match)) end |