Exception: Ecu::MalformedDcmError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/ecu/interfaces/dcm/malformed_dcm_error.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#filecontentObject (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

#linenoObject (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

#contextObject



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_endlineObject



30
# File 'lib/ecu/interfaces/dcm/malformed_dcm_error.rb', line 30

def ctx_endline   = @endline ||= [filecontent.lines.count - 1, lineno + 3].min

#ctx_startlineObject



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_strObject



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_sObject



10
# File 'lib/ecu/interfaces/dcm/malformed_dcm_error.rb', line 10

def to_s = "Malformed DCM: #{super} near line ##{lineno}"

#to_strObject



11
# File 'lib/ecu/interfaces/dcm/malformed_dcm_error.rb', line 11

def to_str = to_s