Class: BulkCsvParser::Result
- Inherits:
-
Object
- Object
- BulkCsvParser::Result
- Defined in:
- lib/bulk_csv_parser/result.rb
Overview
Collects the outcome of a Processor run: how many rows succeeded, how many failed, and the reason each failure happened.
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#failed_count ⇒ Object
readonly
Returns the value of attribute failed_count.
-
#success_count ⇒ Object
readonly
Returns the value of attribute success_count.
Instance Method Summary collapse
- #add_error(row, message) ⇒ Object
- #increment_success(by = 1) ⇒ Object
-
#initialize ⇒ Result
constructor
A new instance of Result.
- #success? ⇒ Boolean
- #to_h ⇒ Object
- #total ⇒ Object
Constructor Details
#initialize ⇒ Result
Returns a new instance of Result.
9 10 11 12 13 |
# File 'lib/bulk_csv_parser/result.rb', line 9 def initialize @success_count = 0 @failed_count = 0 @errors = [] end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
7 8 9 |
# File 'lib/bulk_csv_parser/result.rb', line 7 def errors @errors end |
#failed_count ⇒ Object (readonly)
Returns the value of attribute failed_count.
7 8 9 |
# File 'lib/bulk_csv_parser/result.rb', line 7 def failed_count @failed_count end |
#success_count ⇒ Object (readonly)
Returns the value of attribute success_count.
7 8 9 |
# File 'lib/bulk_csv_parser/result.rb', line 7 def success_count @success_count end |
Instance Method Details
#add_error(row, message) ⇒ Object
19 20 21 22 |
# File 'lib/bulk_csv_parser/result.rb', line 19 def add_error(row, ) @failed_count += 1 @errors << { row: row, error: } end |
#increment_success(by = 1) ⇒ Object
15 16 17 |
# File 'lib/bulk_csv_parser/result.rb', line 15 def increment_success(by = 1) @success_count += by end |
#success? ⇒ Boolean
28 29 30 |
# File 'lib/bulk_csv_parser/result.rb', line 28 def success? failed_count.zero? end |
#to_h ⇒ Object
32 33 34 |
# File 'lib/bulk_csv_parser/result.rb', line 32 def to_h { success_count: success_count, failed_count: failed_count, total: total, errors: errors } end |
#total ⇒ Object
24 25 26 |
# File 'lib/bulk_csv_parser/result.rb', line 24 def total success_count + failed_count end |