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
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_include_tags(line) ⇒ String
Replace the definition’s refs in tags of include statements.
-
#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.
-
#replace_tags_in_included_files(line) ⇒ String
Replace the definition’s refs in included files.
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.
73 74 75 76 77 |
# File 'lib/defmastership/modifier/change_ref.rb', line 73 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.
64 65 66 67 68 69 70 |
# File 'lib/defmastership/modifier/change_ref.rb', line 64 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
59 60 61 |
# File 'lib/defmastership/modifier/change_ref.rb', line 59 def self.replacement_methods i[replace_refdef replace_irefs ] end |
Instance Method Details
#replace_include_tags(line) ⇒ String
Replace the definition’s refs in tags of include statements
107 108 109 110 111 112 113 |
# File 'lib/defmastership/modifier/change_ref.rb', line 107 def (line) return line unless line.match?(Core::DMRegexp::INCLUDE) changes.reduce(line) do |res_line, (from, to)| res_line.sub(/(?<before>tags?=!?([^;]*;)?)#{from}\b/) { "#{$LAST_MATCH_INFO[:before]}#{to}" } end end |
#replace_irefs(line) ⇒ String
Replace the definition’s refs in intenal refs
95 96 97 98 99 100 101 |
# File 'lib/defmastership/modifier/change_ref.rb', line 95 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
83 84 85 86 87 88 89 |
# File 'lib/defmastership/modifier/change_ref.rb', line 83 def replace_refdef(line) if @parsing_state.enabled?(line) do_replace_refdef(line) else line end end |
#replace_tags_in_included_files(line) ⇒ String
Replace the definition’s refs in included files
119 120 121 122 123 124 |
# File 'lib/defmastership/modifier/change_ref.rb', line 119 def (line) if line.match(Core::DMRegexp::INCLUDE) Helper.(Helper::ParsedFilename.full_filename(Regexp.last_match), changes) end line end |