Class: Errata::Erratum::Replace

Inherits:
Errata::Erratum show all
Defined in:
lib/errata/erratum/replace.rb

Constant Summary

Constants inherited from Errata::Erratum

REJECT_ACTIONS, SEMICOLON_DELIMITER, SPECIAL_ABBR

Instance Attribute Summary collapse

Attributes inherited from Errata::Erratum

#matching_expression, #matching_methods, #responder, #section

Instance Method Summary collapse

Methods inherited from Errata::Erratum

#abbr?, #conditions_match?, #expression_matches?, #targets?

Constructor Details

#initialize(responder, options = {}) ⇒ Replace

Returns a new instance of Replace.



6
7
8
9
10
11
12
13
# File 'lib/errata/erratum/replace.rb', line 6

def initialize(responder, options = {})
  super
  @correction = if abbr?
    '\1' + options[:y].to_s + '\2'
  else
    options[:y].to_s
  end
end

Instance Attribute Details

#correctionObject (readonly)

Returns the value of attribute correction.



4
5
6
# File 'lib/errata/erratum/replace.rb', line 4

def correction
  @correction
end

Instance Method Details

#correct!(row) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/errata/erratum/replace.rb', line 15

def correct!(row)
  if targets? row
    if matching_expression.blank?
      row[section] = correction.dup
    else
      row[section].gsub! matching_expression, correction
    end
  end
end