Class: ErrorToCommunicate::ExceptionInfo::Location

Inherits:
Object
  • Object
show all
Defined in:
lib/error_to_communicate/exception_info.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Location

Returns a new instance of Location.



11
12
13
14
15
16
17
# File 'lib/error_to_communicate/exception_info.rb', line 11

def initialize(attributes)
  self.path    = Pathname.new attributes.fetch(:path)
  self.linenum = attributes.fetch :linenum
  self.label   = attributes.fetch :label
  self.pred    = attributes.fetch :pred, nil
  self.succ    = attributes.fetch :succ, nil
end

Instance Attribute Details

#labelObject

Returns the value of attribute label.



9
10
11
# File 'lib/error_to_communicate/exception_info.rb', line 9

def label
  @label
end

#linenumObject

Returns the value of attribute linenum.



9
10
11
# File 'lib/error_to_communicate/exception_info.rb', line 9

def linenum
  @linenum
end

#pathObject

Returns the value of attribute path.



9
10
11
# File 'lib/error_to_communicate/exception_info.rb', line 9

def path
  @path
end

#predObject

Returns the value of attribute pred.



9
10
11
# File 'lib/error_to_communicate/exception_info.rb', line 9

def pred
  @pred
end

#succObject

Returns the value of attribute succ.



9
10
11
# File 'lib/error_to_communicate/exception_info.rb', line 9

def succ
  @succ
end

Class Method Details

.parse(line) ⇒ Object

What if the line doesn’t match for some reason? Raise an exception? Use some reasonable default? (is there one?)



22
23
24
25
26
27
28
29
# File 'lib/error_to_communicate/exception_info.rb', line 22

def self.parse(line)
  line =~ /^(.*?):(\d+):in `(.*?)'$/ # Are ^ and $ sufficient? Should be \A and (\Z or \z)?
  ErrorToCommunicate::ExceptionInfo::Location.new(
    path:    ($1||""),
    linenum: ($2||"-1").to_i,
    label:   ($3||line),
  )
end

Instance Method Details

#==(location) ⇒ Object Also known as: eql?



37
38
39
40
41
# File 'lib/error_to_communicate/exception_info.rb', line 37

def ==(location)
  path    == location.path    &&
  linenum == location.linenum &&
  label   == location.label
end

#hashObject

is there an upper bound I need to stay within? Guessing 30 or 31 bits, but maybe it doesn’t really matter?



33
34
35
# File 'lib/error_to_communicate/exception_info.rb', line 33

def hash
  path.hash + linenum.hash + label.hash
end

#inspectObject



45
46
47
# File 'lib/error_to_communicate/exception_info.rb', line 45

def inspect
  "#<ExInfo::Loc #{path}:#{linenum}:in `#{label}' pred:#{!!pred} succ:#{!!succ}>"
end