Class: Defmastership::Modifier::ChangeRef
- Inherits:
-
Object
- Object
- Defmastership::Modifier::ChangeRef
- Includes:
- ModifierCommon
- Defined in:
- lib/defmastership/modifier/change_ref.rb
Overview
Change references from temporary to definitive with multiple RefChangers
Defined Under Namespace
Modules: Helper
Instance Attribute Summary
Attributes included from ModifierCommon
Class Method Summary collapse
-
.default_config ⇒ Hash{Symbol => Object}
The default configuration.
-
.replacement_methods ⇒ Array<Symbol>
Methods’s symbols will be called in sequence to perform the document modifications.
Instance Method Summary collapse
-
#initialize(config) ⇒ ChangeRef
constructor
A new instance of ChangeRef.
-
#replace_irefs(line) ⇒ String
Replace the definition’s refs in intenal refs.
-
#replace_refdef(line) ⇒ String
Replace the definition’s ref in the line if relevant.
Methods included from ModifierCommon
#do_modifications, #method_missing, #respond_to_missing?, #setup_modifier_module
Constructor Details
#initialize(config) ⇒ ChangeRef
Returns a new instance of ChangeRef.
44 45 46 47 48 |
# File 'lib/defmastership/modifier/change_ref.rb', line 44 def initialize(config) @parsing_state = Core::ParsingState.new setup_modifier_module(config) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Defmastership::Modifier::ModifierCommon
Class Method Details
.default_config ⇒ Hash{Symbol => Object}
Returns the default configuration.
35 36 37 38 39 40 41 |
# File 'lib/defmastership/modifier/change_ref.rb', line 35 def self.default_config { from_regexp: '', to_template: '', next_ref: 0 } end |
.replacement_methods ⇒ Array<Symbol>
Methods’s symbols will be called in sequence to perform the document modifications
30 31 32 |
# File 'lib/defmastership/modifier/change_ref.rb', line 30 def self.replacement_methods %i[replace_refdef replace_irefs] end |
Instance Method Details
#replace_irefs(line) ⇒ String
Replace the definition’s refs in intenal refs
66 67 68 69 70 71 72 |
# File 'lib/defmastership/modifier/change_ref.rb', line 66 def replace_irefs(line) changes.reduce(line) do |res_line, (from, to)| res_line.gsub(Helper.regexp_from(:iref, from)) do Helper.text_with(Regexp.last_match, to) end end end |
#replace_refdef(line) ⇒ String
Replace the definition’s ref in the line if relevant
54 55 56 57 58 59 60 |
# File 'lib/defmastership/modifier/change_ref.rb', line 54 def replace_refdef(line) if @parsing_state.enabled?(line) do_replace_refdef(line) else line end end |