Class: Errata

Inherits:
Object
  • Object
show all
Defined in:
lib/errata.rb,
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

Defined Under Namespace

Classes: Erratum

Constant Summary collapse

ERRATUM_TYPES =
%w{delete replace simplify transform truncate}

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.)



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

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

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

Instance Method Details

#correct!(row) ⇒ Object



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

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

#correctionsObject



58
59
60
# File 'lib/errata.rb', line 58

def corrections
  @_corrections ||= table.rows.map { |hash| hash.symbolize_keys!; "::Errata::Erratum::#{hash[:action].camelcase}".constantize.new(self, hash) if ERRATUM_TYPES.include?(hash[:action]) }.compact
end

#rejectionsObject



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

def rejections
  @_rejections ||= table.rows.map { |hash| hash.symbolize_keys!; ::Errata::Erratum::Reject.new(self, hash) if hash[:action] == 'reject' }.compact
end

#rejects?(row) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/errata.rb', line 45

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

#responderObject



41
42
43
# File 'lib/errata.rb', line 41

def responder
  @_responder ||= (options[:responder].is_a?(String) ? options[:responder].constantize.new : options[:responder])
end

#tableObject



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

def table
  @_table ||= if options[:table].present?
    options[:table]
  else
    RemoteTable.new options.except(:responder)
  end
end