Class: AdLint::Message
- Inherits:
-
Object
show all
- Defined in:
- lib/adlint/message.rb
Overview
DESCRIPTION
Base class of all messages.
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(msg_tmpl, loc, *parts) ⇒ Message
DESCRIPTION
Constructs a message.
PARAMETER
- msg_tmpl
-
MessageTemplate – Template for the creating message.
- loc
-
Location – Location where the message detected.
- parts
-
Array< Object > – Message formatting parts.
77
78
79
80
81
82
|
# File 'lib/adlint/message.rb', line 77
def initialize(msg_tmpl, loc, *parts)
@template = msg_tmpl
@location = loc
@parts = parts
@complements = []
end
|
Instance Attribute Details
#location ⇒ Object
Returns the value of attribute location.
84
85
86
|
# File 'lib/adlint/message.rb', line 84
def location
@location
end
|
Instance Method Details
#complement_with(msg) ⇒ Object
98
99
100
|
# File 'lib/adlint/message.rb', line 98
def complement_with(msg)
@complements.push(msg)
end
|
#eql?(rhs) ⇒ Boolean
102
103
104
|
# File 'lib/adlint/message.rb', line 102
def eql?(rhs)
id == rhs.id && @location == rhs.location && @parts == rhs.parts
end
|
#hash ⇒ Object
106
107
108
|
# File 'lib/adlint/message.rb', line 106
def hash
[id, @location, @parts].hash
end
|
#id ⇒ Object
86
87
88
|
# File 'lib/adlint/message.rb', line 86
def id
@template.message_id
end
|
#must_be_deferred? ⇒ Boolean
94
95
96
|
# File 'lib/adlint/message.rb', line 94
def must_be_deferred?
subclass_responsibility
end
|
#must_be_unique? ⇒ Boolean
90
91
92
|
# File 'lib/adlint/message.rb', line 90
def must_be_unique?
subclass_responsibility
end
|
#print_as_csv(io) ⇒ Object
115
116
117
118
|
# File 'lib/adlint/message.rb', line 115
def print_as_csv(io)
io.puts(to_csv)
@complements.each { |comp| comp.print_as_csv(io) }
end
|
#print_as_str(io) ⇒ Object
110
111
112
113
|
# File 'lib/adlint/message.rb', line 110
def print_as_str(io)
io.puts(to_s)
@complements.each { |comp| comp.print_as_str(io) }
end
|
#to_s ⇒ Object
DESCRIPTION
Converts this message into a string for human readable output.
RETURN VALUE
String – String representation of this message.
125
126
127
128
129
130
131
132
133
134
135
136
|
# 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
|