class AdLint::Message

DESCRIPTION

Base class of all messages.

Attributes

location[R]
parts[R]

Public Class Methods

new(msg_tmpl, loc, *parts) click to toggle source

DESCRIPTION

Constructs a message.

PARAMETER

msg_tmpl

MessageTemplate – Template for the creating message.

loc

LocationLocation where the message detected.

parts

Array< Object > – Message formatting parts.

# File lib/adlint/message.rb, line 77
def initialize(msg_tmpl, loc, *parts)
  @template    = msg_tmpl
  @location    = loc
  @parts       = parts
  @complements = []
end

Public Instance Methods

complement_with(msg) click to toggle source
# File lib/adlint/message.rb, line 98
def complement_with(msg)
  @complements.push(msg)
end
eql?(rhs) click to toggle source
# File lib/adlint/message.rb, line 102
def eql?(rhs)
  id == rhs.id && @location == rhs.location && @parts == rhs.parts
end
hash() click to toggle source
# File lib/adlint/message.rb, line 106
def hash
  [id, @location, @parts].hash
end
id() click to toggle source
# File lib/adlint/message.rb, line 86
def id
  @template.message_id
end
must_be_deferred?() click to toggle source
# File lib/adlint/message.rb, line 94
def must_be_deferred?
  subclass_responsibility
end
must_be_unique?() click to toggle source
# File lib/adlint/message.rb, line 90
def must_be_unique?
  subclass_responsibility
end
print_as_csv(io) click to toggle source
print_as_str(io) click to toggle source
to_s() click to toggle source

DESCRIPTION

Converts this message into a string for human readable output.

RETURN VALUE

StringString representation of this message.

# File lib/adlint/message.rb, line 125
def to_s
  begin
    "#{@location.to_s.to_default_external}:" +
      "#{type_str.to_default_external}:" +
      "#{id.package_name}:#{id.message_name.to_s}:" +
      "#{@template.typical_class.category}:" +
      "#{@template.typical_class.severity}:" +
      "#{@template.format(@parts)}"
  rescue
    raise InvalidMessageFormatError.new(id, @location)
  end
end

Private Instance Methods

to_a() click to toggle source

DESCRIPTION

Converts this message into an array of message elements.

RETURN VALUE

Array< Object > – Array of message elements.

# File lib/adlint/message.rb, line 169
def to_a
  begin
    [
      type.to_s, *@location.to_a, id.package_name, id.message_name,
      @template.typical_class.category, @template.typical_class.severity,
      @template.format(@parts)
    ]
  rescue
    raise InvalidMessageFormatError.new(id, @location)
  end
end
to_csv() click to toggle source
# File lib/adlint/message.rb, line 181
def to_csv
  to_a.map { |obj| obj && obj.to_s.to_default_external }.to_csv
end
type() click to toggle source

DESCRIPTION

Reads the type of this message.

Subclasses must implement this method.

RETURN VALUE

SymbolMessage type symbol.

# File lib/adlint/message.rb, line 149
def type
  subclass_responsibility
end
type_str() click to toggle source

DESCRIPTION

Reads the type string of this message.

Subclasses must implement this method.

RETURN VALUE

StringMessage type string.

# File lib/adlint/message.rb, line 160
def type_str
  subclass_responsibility
end