Class: RCheck::Backtrace::Line

Inherits:
Object
  • Object
show all
Defined in:
lib/rcheck/backtrace.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str) ⇒ Line

Returns a new instance of Line.



14
15
16
17
18
19
# File 'lib/rcheck/backtrace.rb', line 14

def initialize(str)
  @file, @line, @scope = str.split(':')
  @line = line.to_i
  @file = Pathname.new(File.expand_path(file)).
          relative_path_from Pathname.new(Dir.pwd)
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



13
14
15
# File 'lib/rcheck/backtrace.rb', line 13

def file
  @file
end

#lineObject (readonly)

Returns the value of attribute line.



13
14
15
# File 'lib/rcheck/backtrace.rb', line 13

def line
  @line
end

Instance Method Details

#scopeObject



25
26
27
# File 'lib/rcheck/backtrace.rb', line 25

def scope
  @scope[4..-2]
end

#shortObject



21
22
23
# File 'lib/rcheck/backtrace.rb', line 21

def short
  "#{@file}:#{@line}"
end

#sourceObject



33
34
35
36
# File 'lib/rcheck/backtrace.rb', line 33

def source
  src = File.readlines(File.expand_path(@file))[@line-1]
  src && src.strip
end

#to_sObject



29
30
31
# File 'lib/rcheck/backtrace.rb', line 29

def to_s
  "%-30s %s" % [short, scope]
end