Class: Errata::Erratum::Transform

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

Constant Summary collapse

ALLOWED_METHODS =
%w{upcase downcase}

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 = {}) ⇒ Transform

Returns a new instance of Transform.



7
8
9
10
11
12
# File 'lib/erratum/transform.rb', line 7

def initialize(errata, options = {})
  super
  set_matching_expression(options)
  @string_method = options[:y]
  raise "string method (#{@string_method}) needs to be in (#{ALLOWED_METHODS.join(', ')})" unless ALLOWED_METHODS.include?(@string_method)
end

Instance Attribute Details

#matching_expressionObject

Returns the value of attribute matching_expression.



5
6
7
# File 'lib/erratum/transform.rb', line 5

def matching_expression
  @matching_expression
end

#string_methodObject

Returns the value of attribute string_method.



5
6
7
# File 'lib/erratum/transform.rb', line 5

def string_method
  @string_method
end

Instance Method Details

#correct!(row) ⇒ Object



18
19
20
21
22
# File 'lib/erratum/transform.rb', line 18

def correct!(row)
  super(row) do
    row[column].gsub!(matching_expression) { |match| match.send(string_method) }
  end
end

#inspectObject



14
15
16
# File 'lib/erratum/transform.rb', line 14

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