Class: Errata::Erratum::Replace

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

Instance Attribute Summary collapse

Attributes inherited from Errata::Erratum

#column, #errata, #options

Instance Method Summary collapse

Methods inherited from Errata::Erratum

#conditions_match?, #expression_matches?, #matching_methods, #set_matching_expression, #targets?

Constructor Details

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



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

def initialize(errata, options = {})
  super
  set_matching_expression(options)
  @correction = /\Aabbr\((.*)\)\z/.match(options[:x]) ? '\1' + options[:y].to_s + '\2' : options[:y].to_s
end

Instance Attribute Details

#correctionObject

Returns the value of attribute correction.



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

def correction
  @correction
end

#matching_expressionObject

Returns the value of attribute matching_expression.



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

def matching_expression
  @matching_expression
end

Instance Method Details

#correct!(row) ⇒ Object



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

def correct!(row)
  super(row) do
    if matching_expression.blank?
      row[column] = correction
    else
      row[column].gsub!(matching_expression, correction)
    end
  end
end

#inspectObject



12
13
14
# File 'lib/erratum/replace.rb', line 12

def inspect
  super + " matching_expression=#{matching_expression} correction=#{correction}>"
end