Class: CodeMessage

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/codemessage.rb

Overview

warnings and errors from code compilation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, linenumber, colnumber, messagetype, message) ⇒ CodeMessage

Returns a new instance of CodeMessage



9
10
11
12
13
14
15
# File 'lib/codemessage.rb', line 9

def initialize(filename, linenumber, colnumber, messagetype, message)
  @filename = filename
  @linenumber = linenumber
  @colnumber = colnumber
  @messagetype = messagetype
  @message = message
end

Instance Attribute Details

#colnumberObject (readonly)

Returns the value of attribute colnumber



6
7
8
# File 'lib/codemessage.rb', line 6

def colnumber
  @colnumber
end

#filenameObject (readonly)

Returns the value of attribute filename



6
7
8
# File 'lib/codemessage.rb', line 6

def filename
  @filename
end

#linenumberObject (readonly)

Returns the value of attribute linenumber



6
7
8
# File 'lib/codemessage.rb', line 6

def linenumber
  @linenumber
end

#messageObject

Returns the value of attribute message



7
8
9
# File 'lib/codemessage.rb', line 7

def message
  @message
end

#messagetypeObject (readonly)

Returns the value of attribute messagetype



6
7
8
# File 'lib/codemessage.rb', line 6

def messagetype
  @messagetype
end

Instance Method Details

#<=>(other) ⇒ Boolean

Checks if two CodeMessage objects are different

Parameters:

  • other (CodeMessage)

    a second CodeMessage instance to compare against self

Returns:

  • (Boolean)

    false if the objects are data-equal, true otherwise



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/codemessage.rb', line 50

def <=>(other)
  f = @filename <=> other.filename
  l = @linenumber.to_i <=> other.linenumber.to_i
  c = @colnumber.to_i <=> other.colnumber.to_i
  mt = @messagetype <=> other.messagetype
  m = @message[0..10] <=> other.message[0..10]

  if f != 0
    f
  elsif l != 0
    l
  elsif c != 0
    c
  elsif mt != 0
    mt
  else
    m
  end
end

#eql?(other) ⇒ Boolean

Checks if two CodeMessage objects are equal

Parameters:

  • other (CodeMessage)

    a second CodeMessage instance to compare against self

Returns:

  • (Boolean)

    true if the objects are data-equal, false otherwise



42
43
44
# File 'lib/codemessage.rb', line 42

def eql?(other)
  (self <=> other).zero?
end

#error?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/codemessage.rb', line 24

def error?
  @messagetype =~ /.*err.*/i
end

#hashObject



34
35
36
# File 'lib/codemessage.rb', line 34

def hash
  inspect.hash
end

#inspectObject



28
29
30
31
32
# File 'lib/codemessage.rb', line 28

def inspect
  hash = {}
  instance_variables.each { |var| hash[var.to_s.delete('@')] = instance_variable_get(var) }
  hash
end

#warning?Boolean

Checks if this instance constitutes a warning

Returns:

  • (Boolean)

    true if the code message is a warning, false otherwise



20
21
22
# File 'lib/codemessage.rb', line 20

def warning?
  @messagetype =~ /.*warn.*/i
end