Class: Errata
- Inherits:
-
Object
- Object
- Errata
- 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
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #correct!(row) ⇒ Object
- #corrections ⇒ Object
-
#initialize(options = {}) ⇒ Errata
constructor
Arguments *
:responder
(required) - normally you pass this something like Guru.new, which should respond to questions like #is_a_bentley?. - #rejections ⇒ Object
- #rejects?(row) ⇒ Boolean
- #responder ⇒ Object
- #table ⇒ Object
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( = {}) .symbolize_keys! @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
22 23 24 |
# File 'lib/errata.rb', line 22 def @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 |
#corrections ⇒ Object
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 |
#rejections ⇒ Object
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
45 46 47 |
# File 'lib/errata.rb', line 45 def rejects?(row) rejections.any? { |erratum| erratum.targets?(row) } end |
#responder ⇒ Object
41 42 43 |
# File 'lib/errata.rb', line 41 def responder @_responder ||= ([:responder].is_a?(String) ? [:responder].constantize.new : [:responder]) end |
#table ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/errata.rb', line 33 def table @_table ||= if [:table].present? [:table] else RemoteTable.new .except(:responder) end end |