Class: ErrorToCommunicate::ExceptionInfo::Location
- Inherits:
-
Object
- Object
- ErrorToCommunicate::ExceptionInfo::Location
- Defined in:
- lib/error_to_communicate/exception_info.rb
Instance Attribute Summary collapse
-
#binding ⇒ Object
Returns the value of attribute binding.
-
#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, binding) ⇒ 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 18 |
# 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 self.binding = attributes.fetch :binding end |
Instance Attribute Details
#binding ⇒ Object
Returns the value of attribute binding.
9 10 11 |
# File 'lib/error_to_communicate/exception_info.rb', line 9 def binding @binding end |
#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, binding) ⇒ Object
What if the line doesn’t match for some reason? Raise an exception? Use some reasonable default? (is there one?)
23 24 25 26 27 28 29 30 31 |
# File 'lib/error_to_communicate/exception_info.rb', line 23 def self.parse(line, binding) 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), binding: binding ) end |
Instance Method Details
#==(location) ⇒ Object Also known as: eql?
39 40 41 42 43 |
# File 'lib/error_to_communicate/exception_info.rb', line 39 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?
35 36 37 |
# File 'lib/error_to_communicate/exception_info.rb', line 35 def hash path.hash + linenum.hash + label.hash end |
#inspect ⇒ Object
47 48 49 |
# File 'lib/error_to_communicate/exception_info.rb', line 47 def inspect "#<ExInfo::Loc #{path}:#{linenum}:in `#{label}' pred:#{!!pred} succ:#{!!succ}>" end |