Exception: Ecu::MalformedDcmError
- Inherits:
-
StandardError
- Object
- StandardError
- Ecu::MalformedDcmError
- Defined in:
- lib/ecu/interfaces/dcm/malformed_dcm_error.rb
Instance Attribute Summary collapse
-
#filecontent ⇒ Object
readonly
Returns the value of attribute filecontent.
-
#lineno ⇒ Object
readonly
Returns the value of attribute lineno.
Instance Method Summary collapse
- #context ⇒ Object
- #ctx_endline ⇒ Object
- #ctx_startline ⇒ Object
- #fmt(n) ⇒ Object
- #fmt_str ⇒ Object
-
#initialize(msg, lineno, filecontent) ⇒ MalformedDcmError
constructor
A new instance of MalformedDcmError.
- #present(line, n, highlight) ⇒ Object
- #to_s ⇒ Object
- #to_str ⇒ Object
Constructor Details
#initialize(msg, lineno, filecontent) ⇒ MalformedDcmError
Returns a new instance of MalformedDcmError.
4 5 6 7 8 |
# File 'lib/ecu/interfaces/dcm/malformed_dcm_error.rb', line 4 def initialize(msg, lineno, filecontent) super(msg) @lineno = lineno @filecontent = filecontent end |
Instance Attribute Details
#filecontent ⇒ Object (readonly)
Returns the value of attribute filecontent.
3 4 5 |
# File 'lib/ecu/interfaces/dcm/malformed_dcm_error.rb', line 3 def filecontent @filecontent end |
#lineno ⇒ Object (readonly)
Returns the value of attribute lineno.
3 4 5 |
# File 'lib/ecu/interfaces/dcm/malformed_dcm_error.rb', line 3 def lineno @lineno end |
Instance Method Details
#context ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/ecu/interfaces/dcm/malformed_dcm_error.rb', line 13 def context filecontent .lines .each .with_index(1) .map { |line, n| present(line, n, n == lineno) } .then { _1[ctx_startline..ctx_endline] } end |
#ctx_endline ⇒ Object
30 |
# File 'lib/ecu/interfaces/dcm/malformed_dcm_error.rb', line 30 def ctx_endline = @endline ||= [filecontent.lines.count - 1, lineno + 3].min |
#ctx_startline ⇒ Object
29 |
# File 'lib/ecu/interfaces/dcm/malformed_dcm_error.rb', line 29 def ctx_startline = [0, lineno - 7].max |
#fmt(n) ⇒ Object
32 |
# File 'lib/ecu/interfaces/dcm/malformed_dcm_error.rb', line 32 def fmt(n) = fmt_str % n |
#fmt_str ⇒ Object
31 |
# File 'lib/ecu/interfaces/dcm/malformed_dcm_error.rb', line 31 def fmt_str = "%#{(ctx_endline + 1).to_s.length}d" |
#present(line, n, highlight) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/ecu/interfaces/dcm/malformed_dcm_error.rb', line 22 def present(line, n, highlight) case highlight when true then fmt(n) + " => | " + line when false then fmt(n) + " | " + line end end |
#to_s ⇒ Object
10 |
# File 'lib/ecu/interfaces/dcm/malformed_dcm_error.rb', line 10 def to_s = "Malformed DCM: #{super} near line ##{lineno}" |
#to_str ⇒ Object
11 |
# File 'lib/ecu/interfaces/dcm/malformed_dcm_error.rb', line 11 def to_str = to_s |