Class: DefMastership::UpdateDefVersionLineModifier

Inherits:
LineModifierBase show all
Defined in:
lib/defmastership/update_def_version_line_modifier.rb

Overview

modify one line after another

Instance Attribute Summary collapse

Attributes inherited from LineModifierBase

#changes, #config

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from LineModifierBase

#from_config, #method_missing, #respond_to_missing?

Constructor Details

#initializeUpdateDefVersionLineModifier

Returns a new instance of UpdateDefVersionLineModifier.



13
14
15
16
17
18
19
20
# File 'lib/defmastership/update_def_version_line_modifier.rb', line 13

def initialize
  super
  @config = {
    def_type: '',
    ref_document: '',
    first_version: ''
  }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class DefMastership::LineModifierBase

Instance Attribute Details

#documentObject

Returns the value of attribute document.



7
8
9
# File 'lib/defmastership/update_def_version_line_modifier.rb', line 7

def document
  @document
end

#ref_documentObject

Returns the value of attribute ref_document.



7
8
9
# File 'lib/defmastership/update_def_version_line_modifier.rb', line 7

def ref_document
  @ref_document
end

Class Method Details

.from_config(hash) ⇒ Object



9
10
11
# File 'lib/defmastership/update_def_version_line_modifier.rb', line 9

def self.from_config(hash)
  new.from_config(hash)
end

Instance Method Details

#replace(line) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/defmastership/update_def_version_line_modifier.rb', line 22

def replace(line)
  match = matched?(line)

  return line unless match
  return line unless match[:type] == def_type

  version_and_checksum = ''
  if match[:explicit_checksum] || version_string(match)
    version_and_checksum = "(#{version_string(match)}#{match[:explicit_checksum]})"
  end

  line.gsub(Regexp.new("#{match[:reference]}#{DMRegexp::DEF_VERSION_AND_CHECKSUM}")) do
    "#{match[:reference]}#{version_and_checksum}"
  end
end