Class: ActiveSanction::Parsers::Warning
- Inherits:
-
Object
- Object
- ActiveSanction::Parsers::Warning
- 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
-
#line ⇒ Integer?
readonly
nil when the parser cannot say which line -- see above.
- #message ⇒ String readonly
- #snippet ⇒ String? readonly
Instance Method Summary collapse
- #initialize(line:, message:, snippet: nil) ⇒ void constructor
- #inspect ⇒ String
- #to_h ⇒ Hash{Symbol => T.untyped}
- #to_s ⇒ String
Constructor Details
#initialize(line:, message:, snippet: nil) ⇒ void
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(, 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.
47 48 49 |
# File 'lib/active_sanction/parsers.rb', line 47 def line @line end |
#message ⇒ String (readonly)
50 51 52 |
# File 'lib/active_sanction/parsers.rb', line 50 def @message end |
#snippet ⇒ String? (readonly)
53 54 55 |
# File 'lib/active_sanction/parsers.rb', line 53 def snippet @snippet end |
Instance Method Details
#inspect ⇒ String
72 |
# File 'lib/active_sanction/parsers.rb', line 72 def inspect = "#<#{self.class} #{self}>" |
#to_h ⇒ Hash{Symbol => T.untyped}
69 |
# File 'lib/active_sanction/parsers.rb', line 69 def to_h = { line: line, message: , snippet: snippet } |
#to_s ⇒ String
64 65 66 |
# File 'lib/active_sanction/parsers.rb', line 64 def to_s "#{"line #{line}: " if line}#{}#{" -- #{snippet.inspect}" if snippet}" end |