Class: InvalidRecordFinder::FindingsList

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/invalid_record_finder/findings_list.rb

Instance Method Summary collapse

Constructor Details

#initialize(data = []) ⇒ FindingsList

Returns a new instance of FindingsList.



9
10
11
# File 'lib/invalid_record_finder/findings_list.rb', line 9

def initialize(data = [])
  @findings = data
end

Instance Method Details

#==(other) ⇒ Object



43
44
45
# File 'lib/invalid_record_finder/findings_list.rb', line 43

def ==(other)
  other.is_a?(self.class) && other.to_a == to_a
end

#add_if_invalid(record) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/invalid_record_finder/findings_list.rb', line 13

def add_if_invalid(record)
  return if record.valid? # Just make sure that the validation has run

  record.errors.each do |err|
    findings << InvalidRecordFinder::Finding.new(
      record, err.attribute.to_s, err.message
    )
  end
rescue => e
  # handle and report exceptions that occur during validation
  findings << InvalidRecordFinder::Finding.new(record, 'EXCEPTION', e.message)
end

#to_csvObject



36
37
38
39
40
41
# File 'lib/invalid_record_finder/findings_list.rb', line 36

def to_csv
  CSV.generate do |csv|
    csv << headers
    findings.map(&:to_a).each { |line| csv << line }
  end
end

#to_tableObject



28
29
30
31
32
# File 'lib/invalid_record_finder/findings_list.rb', line 28

def to_table
  Tabulo::Table.new(findings.first(100), *headers, align_header: :left)
    .autosize_columns
    .shrink_to(:screen, except: :id)
end