Class: ActiveSanction::Parsers::Warning

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/active_sanction/parsers.rb

Overview

One row the parser could not use, kept rather than raised.

A sanctions list is not a file we control. OFAC ships 19,321 rows and a single unbalanced quote somewhere in the middle must not cost the other 19,320 -- refusing to load a list because one record is malformed fails exactly when the list is most needed. So a bad row is recorded here and skipped, and the caller decides whether the count is tolerable.

line is the line number within the file, which is what makes a warning actionable: a 5.6 MB CSV is only debuggable if the complaint says where. It is nil when the parser cannot say -- libxml2 reports no position for a record -- and a warning that cannot point at a line still says what went wrong rather than pointing at the wrong one.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(line:, message:, snippet: nil) ⇒ void

Parameters:

  • line (Integer, nil)
  • message (String)
  • snippet (T.untyped) (defaults to: nil)


56
57
58
59
60
61
# File 'lib/active_sanction/parsers.rb', line 56

def initialize(line:, message:, snippet: nil)
  @line = T.let(line, T.nilable(Integer))
  @message = T.let(message, String)
  @snippet = T.let(snippet.nil? ? nil : truncate(snippet), T.nilable(String))
  freeze
end

Instance Attribute Details

#line ⇒ Integer? (readonly)

nil when the parser cannot say which line -- see above.

Returns:

  • (Integer, nil)


47
48
49
# File 'lib/active_sanction/parsers.rb', line 47

def line
  @line
end

#message ⇒ String (readonly)

Returns:

  • (String)


50
51
52
# File 'lib/active_sanction/parsers.rb', line 50

def message
  @message
end

#snippet ⇒ String? (readonly)

Returns:

  • (String, nil)


53
54
55
# File 'lib/active_sanction/parsers.rb', line 53

def snippet
  @snippet
end

Instance Method Details

#inspect ⇒ String

Returns:

  • (String)


72
# File 'lib/active_sanction/parsers.rb', line 72

def inspect = "#<#{self.class} #{self}>"

#to_h ⇒ Hash{Symbol => T.untyped}

Returns:

  • (Hash{Symbol => T.untyped})


69
# File 'lib/active_sanction/parsers.rb', line 69

def to_h = { line: line, message: message, snippet: snippet }

#to_s ⇒ String

Returns:

  • (String)


64
65
66
# File 'lib/active_sanction/parsers.rb', line 64

def to_s
  "#{"line #{line}: " if line}#{message}#{" -- #{snippet.inspect}" if snippet}"
end