Exception: TermUtils::AP::ParseError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/term_utils/ap.rb

Overview

ParseError.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(props = {}) ⇒ ParseError

Constructs a new ParseError.



33
34
35
36
# File 'lib/term_utils/ap.rb', line 33

def initialize(props = {})
  super(self.class.create_message(props))
  @props = props.dup
end

Class Method Details

.create_message(props) ⇒ String

Creates a message based on given properties.



77
78
79
80
81
82
83
84
85
86
87
# File 'lib/term_utils/ap.rb', line 77

def self.create_message(props)
  props = props.dup
  msg = props.delete(:message) { |key| raise StandardError, "#{key} property is mandatory" }
  return msg if props.empty?

  vals = []
  props.each do |key, val|
    vals << "#{key}: \"#{val}\""
  end
  "#{msg} (#{vals.join(', ')})"
end

Instance Method Details

#faultString?

Returns the faulty argument (if any).



70
71
72
# File 'lib/term_utils/ap.rb', line 70

def fault
  @props.fetch(:fault, nil)
end

#fault?Boolean

Tests whether this one has a faulty argument.



64
65
66
# File 'lib/term_utils/ap.rb', line 64

def fault?
  @props.key?(:fault)
end

#parameterSymbol?

Returns the syntax parameter ID (if any).



58
59
60
# File 'lib/term_utils/ap.rb', line 58

def parameter
  @props.fetch(:parameter, nil)
end

#parameter?Boolean

Tests whether this one has a syntax parameter ID.



52
53
54
# File 'lib/term_utils/ap.rb', line 52

def parameter?
  @props.key?(:parameter)
end

#propsHash<Symbol, Object>

Returns the properties associated to this one.



40
41
42
# File 'lib/term_utils/ap.rb', line 40

def props
  @props.dup
end

#short_messageString

Returns the short message (i.e. the message without properties).



46
47
48
# File 'lib/term_utils/ap.rb', line 46

def short_message
  @props.fetch(:message)
end