Class: Errata

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

Defined Under Namespace

Classes: Erratum

Constant Summary collapse

ERRATUM_TYPES =
%w{delete replace simplify transform truncate reject}
VERSION =
'1.0.2'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Errata

Arguments

  • 'responder' (required) - normally you pass this something like Guru.new, which should respond to questions like #is_a_bentley?. If you pass a string, it will be lazily constantized and a new object initialized from it; for example, 'Guru' will lead to 'Guru'.constantize.new.

  • 'table' - takes something that acts like a RemoteTable

If and only if you don't pass 'table', all other options will be passed to a new RemoteTable (for example, 'url', etc.)


22
23
24
25
# File 'lib/errata.rb', line 22

def initialize(options = {})
  @options = options.dup
  @options.stringify_keys!
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.


16
17
18
# File 'lib/errata.rb', line 16

def options
  @options
end

Instance Method Details

#correct!(row) ⇒ Object


35
36
37
38
# File 'lib/errata.rb', line 35

def correct!(row)
  corrections.each { |erratum| erratum.correct!(row) }
  nil
end

#correctionsObject


53
54
55
# File 'lib/errata.rb', line 53

def corrections
  errata.select { |erratum| not erratum.is_a? ::Errata::Erratum::Reject }
end

#errataObject


40
41
42
43
44
45
46
47
# File 'lib/errata.rb', line 40

def errata
  @errata ||= (options['table'] ? options['table'] : ::RemoteTable.new(options.except('responder'))).inject([]) do |memo, erratum_description|
    if ERRATUM_TYPES.include? erratum_description['action']
      memo.push "::Errata::Erratum::#{erratum_description['action'].camelcase}".constantize.new self, erratum_description
    end
    memo
  end
end

#rejectionsObject


49
50
51
# File 'lib/errata.rb', line 49

def rejections
  errata.select { |erratum| erratum.is_a? ::Errata::Erratum::Reject }
end

#rejects?(row) ⇒ Boolean

Returns:

  • (Boolean)

31
32
33
# File 'lib/errata.rb', line 31

def rejects?(row)
  rejections.any? { |erratum| erratum.targets?(row) }
end

#responderObject


27
28
29
# File 'lib/errata.rb', line 27

def responder
  options['responder'].is_a?(::String) ? options['responder'].constantize.new : options['responder']
end