Class: ErrorToCommunicate::ExceptionInfo::Location
- Inherits:
-
Object
- Object
- ErrorToCommunicate::ExceptionInfo::Location
- Defined in:
- lib/error_to_communicate/exception_info.rb
Instance Attribute Summary collapse
-
#label ⇒ Object
Returns the value of attribute label.
-
#linenum ⇒ Object
Returns the value of attribute linenum.
-
#path ⇒ Object
Returns the value of attribute path.
-
#pred ⇒ Object
Returns the value of attribute pred.
-
#succ ⇒ Object
Returns the value of attribute succ.
Class Method Summary collapse
-
.parse(line) ⇒ Object
What if the line doesn’t match for some reason? Raise an exception? Use some reasonable default? (is there one?).
Instance Method Summary collapse
- #==(location) ⇒ Object (also: #eql?)
-
#hash ⇒ Object
is there an upper bound I need to stay within? Guessing 30 or 31 bits, but maybe it doesn’t really matter?.
-
#initialize(attributes) ⇒ Location
constructor
A new instance of Location.
- #inspect ⇒ Object
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
#label ⇒ Object
Returns the value of attribute label.
9 10 11 |
# File 'lib/error_to_communicate/exception_info.rb', line 9 def label @label end |
#linenum ⇒ Object
Returns the value of attribute linenum.
9 10 11 |
# File 'lib/error_to_communicate/exception_info.rb', line 9 def linenum @linenum end |
#path ⇒ Object
Returns the value of attribute path.
9 10 11 |
# File 'lib/error_to_communicate/exception_info.rb', line 9 def path @path end |
#pred ⇒ Object
Returns the value of attribute pred.
9 10 11 |
# File 'lib/error_to_communicate/exception_info.rb', line 9 def pred @pred end |
#succ ⇒ Object
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 |
#hash ⇒ Object
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 |
#inspect ⇒ Object
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 |