Class: Kefka::Method
- Inherits:
-
Object
- Object
- Kefka::Method
- Defined in:
- lib/kefka.rb
Instance Attribute Summary collapse
-
#classname ⇒ Object
readonly
Returns the value of attribute classname.
-
#depth ⇒ Object
Returns the value of attribute depth.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#format ⇒ Object
Returns the value of attribute format.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#line ⇒ Object
readonly
Returns the value of attribute line.
-
#source ⇒ Object
Returns the value of attribute source.
Instance Method Summary collapse
- #contains?(file, line) ⇒ Boolean
- #end_line ⇒ Object
- #eql?(other) ⇒ Boolean (also: #==)
- #formatted_source ⇒ Object
- #hash ⇒ Object
-
#initialize(options = {}) ⇒ Method
constructor
A new instance of Method.
- #key ⇒ Object
- #source_at_line(line) ⇒ Object
- #source_location ⇒ Object
- #to_json(*a) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Method
Returns a new instance of Method.
49 50 51 52 53 54 55 56 |
# File 'lib/kefka.rb', line 49 def initialize(={}) raise ArgumentError, "missing file + line" unless [:file] && [:line] @classname = [:classname] @id = [:id] @file = [:file] @start_line = [:line] @format = [:format] || :plain end |
Instance Attribute Details
#classname ⇒ Object (readonly)
Returns the value of attribute classname.
46 47 48 |
# File 'lib/kefka.rb', line 46 def classname @classname end |
#depth ⇒ Object
Returns the value of attribute depth.
47 48 49 |
# File 'lib/kefka.rb', line 47 def depth @depth end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
46 47 48 |
# File 'lib/kefka.rb', line 46 def file @file end |
#format ⇒ Object
Returns the value of attribute format.
47 48 49 |
# File 'lib/kefka.rb', line 47 def format @format end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
46 47 48 |
# File 'lib/kefka.rb', line 46 def id @id end |
#line ⇒ Object (readonly)
Returns the value of attribute line.
46 47 48 |
# File 'lib/kefka.rb', line 46 def line @line end |
#source ⇒ Object
Returns the value of attribute source.
47 48 49 |
# File 'lib/kefka.rb', line 47 def source @source end |
Instance Method Details
#contains?(file, line) ⇒ Boolean
70 71 72 |
# File 'lib/kefka.rb', line 70 def contains?(file, line) @file == file && @start_line <= line && end_line > line end |
#end_line ⇒ Object
62 63 64 |
# File 'lib/kefka.rb', line 62 def end_line @start_line + source.lines.count - 1 end |
#eql?(other) ⇒ Boolean Also known as: ==
102 103 104 |
# File 'lib/kefka.rb', line 102 def eql?(other) self.key == other.key end |
#formatted_source ⇒ Object
83 84 85 86 87 88 89 90 |
# File 'lib/kefka.rb', line 83 def formatted_source if @format == :html CodeRay.scan(source, :ruby) .div(:line_numbers => :table, :line_number_start => @start_line) else source end end |
#hash ⇒ Object
108 109 110 |
# File 'lib/kefka.rb', line 108 def hash [@file,@start_line].hash end |
#key ⇒ Object
66 67 68 |
# File 'lib/kefka.rb', line 66 def key source_location ? [id,source_location].flatten.join(":") : nil end |
#source_at_line(line) ⇒ Object
92 93 94 95 96 |
# File 'lib/kefka.rb', line 92 def source_at_line(line) # what if source is not known, ie. eval index = line - @start_line source.lines.take(index + 1)[index] end |
#source_location ⇒ Object
58 59 60 |
# File 'lib/kefka.rb', line 58 def source_location [@file,@start_line] end |
#to_json(*a) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/kefka.rb', line 112 def to_json(*a) { :classname => @classname, :id => @id.to_s, :file => @file, :line => @start_line, :end_line => end_line, :depth => depth, :source => formatted_source }.to_json(*a) end |
#to_s ⇒ Object
98 99 100 |
# File 'lib/kefka.rb', line 98 def to_s "#{classname} #{id}" end |