Class: OCL::Label

Inherits:
Object
  • Object
show all
Defined in:
lib/dbc/ocl.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, file, line) ⇒ Label

Returns a new instance of Label.



24
25
26
27
28
29
30
31
# File 'lib/dbc/ocl.rb', line 24

def initialize(message, file, line)
	@message = message
	if message =~ /[\n\r"]/
		raise ParseError, "label '#{message}' contains invalid characters: '\\n', '\\r', or '\"'"
	end
	@file = file
	@line = line
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



33
34
35
# File 'lib/dbc/ocl.rb', line 33

def file
  @file
end

#lineObject (readonly)

Returns the value of attribute line.



33
34
35
# File 'lib/dbc/ocl.rb', line 33

def line
  @line
end

#messageObject (readonly)

Returns the value of attribute message.



33
34
35
# File 'lib/dbc/ocl.rb', line 33

def message
  @message
end

Instance Method Details

#to_s(context = nil) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/dbc/ocl.rb', line 35

def to_s(context = nil)
	if @file
		tag = "\"#{@file}:#{@line}: "
	else
		tag = " __FILE__ \":#{@line}: "
	end
	# C string is open
	tag << context << ': ' if context
	tag << ' ' << @message if @message
	tag << "\"" # close C string
end