Class: Errata::Erratum::Simplify

Inherits:
Errata::Erratum show all
Defined in:
lib/erratum/simplify.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

Constructor Details

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

Returns a new instance of Simplify.



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

def initialize(errata, options = {})
  super
  @second_column = options[:x]
end

Instance Attribute Details

#second_columnObject

Returns the value of attribute second_column.



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

def second_column
  @second_column
end

Instance Method Details

#correct!(row) ⇒ Object



19
20
21
22
23
# File 'lib/erratum/simplify.rb', line 19

def correct!(row)
  super(row) do
    row[column].gsub!(matching_expression(row), '')
  end
end

#inspectObject



11
12
13
# File 'lib/erratum/simplify.rb', line 11

def inspect
  super + " second_column=#{second_column}>"
end

#matching_expression(row) ⇒ Object



25
26
27
28
# File 'lib/erratum/simplify.rb', line 25

def matching_expression(row)
  @_matching_expressions ||= {}
  @_matching_expressions[row[second_column]] ||= /[\s\(\[\'\"]*#{Regexp.escape(row[second_column])}[\s\)\]\'\"]*/
end

#targets?(row) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/erratum/simplify.rb', line 15

def targets?(row)
  !row[column].blank? and !row[second_column].blank? and conditions_match?(row) and matching_expression(row).match(row[column])
end