Class: Errata::Erratum

Inherits:
Object
  • Object
show all
Defined in:
lib/erratum.rb,
lib/erratum/delete.rb,
lib/erratum/reject.rb,
lib/erratum/replace.rb,
lib/erratum/simplify.rb,
lib/erratum/truncate.rb,
lib/erratum/transform.rb

Direct Known Subclasses

Delete, Reject, Replace, Simplify, Transform, Truncate

Defined Under Namespace

Classes: Delete, Reject, Replace, Simplify, Transform, Truncate

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Erratum.



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

def initialize(errata, options = {})
  raise "you can't set this from outside" if options.has_key?(:prefix)
  @errata = errata
  @column = options[:section]
  @matching_method = "#{options[:condition].gsub(/[^a-z0-9]/i, '_').downcase}?".to_sym if options[:condition]
end

Instance Attribute Details

#columnObject

Returns the value of attribute column.



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

def column
  @column
end

#errataObject

Returns the value of attribute errata.



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

def errata
  @errata
end

#matching_methodObject

Returns the value of attribute matching_method.



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

def matching_method
  @matching_method
end

Instance Method Details

#correct!(row, &block) ⇒ Object



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

def correct!(row, &block)
  return :skipped unless targets?(row)
  # old_value = row[column].to_s.dup
  yield if block_given?
  # unless name.demodulize.underscore == 'truncate' or name.demodulize.underscore == 'simplify'
  #   puts "-" * 64
  #   puts inspect
  #   puts row.inspect
  #   if row[column] != old_value
  #     puts "#{old_value} -> #{row[column]}"
  #   else
  #     puts "no change"
  #   end
  #   puts
  # end
  :corrected
end

#inspectObject



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

def inspect
  "<#{self.class.name}:#{object_id} klass=#{klass.name} column=#{column} matching_method=#{matching_method}"
end

#targets?(row) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/erratum.rb', line 17

def targets?(row)
  !!(method_matches?(row) and expression_matches?(row))
end