class CSVImporter::ReportMessage

Generate a human readable message for the given report.

Attributes

report[RW]

Public Class Methods

call(report) click to toggle source
# File lib/csv_importer/report_message.rb, line 4
def self.call(report)
  new(report).to_s
end
new(report) click to toggle source
# File lib/csv_importer/report_message.rb, line 8
def initialize(report)
  @report = report
end

Public Instance Methods

to_s() click to toggle source
# File lib/csv_importer/report_message.rb, line 14
def to_s
  send("report_#{report.status}")
end

Private Instance Methods

import_details() click to toggle source

Generate something like: “3 created. 4 updated. 1 failed to create. 2 failed to update.”

# File lib/csv_importer/report_message.rb, line 45
def import_details
  report.attributes
    .select { |name, _| name["_rows"] }
    .select { |_, instances| instances.size > 0 }
    .map { |bucket, instances| "#{instances.size} #{bucket.to_s.gsub('_rows', '').gsub('_', ' ')}" }
    .join(", ")
end
report_aborted() click to toggle source
# File lib/csv_importer/report_message.rb, line 40
def report_aborted
  "Import aborted"
end
report_done() click to toggle source
# File lib/csv_importer/report_message.rb, line 28
def report_done
  "Import completed: " + import_details
end
report_in_progress() click to toggle source
# File lib/csv_importer/report_message.rb, line 24
def report_in_progress
  "Import in progress"
end
report_invalid_csv_file() click to toggle source
# File lib/csv_importer/report_message.rb, line 36
def report_invalid_csv_file
  report.parser_error
end
report_invalid_header() click to toggle source
# File lib/csv_importer/report_message.rb, line 32
def report_invalid_header
  "The following columns are required: #{report.missing_columns.join(", ")}"
end
report_pending() click to toggle source
# File lib/csv_importer/report_message.rb, line 20
def report_pending
  "Import hasn't started yet"
end