Class: CC::Analyzer::Formatters::HTMLFormatter::Location

Inherits:
Object
  • Object
show all
Defined in:
lib/cc/analyzer/formatters/html_formatter.rb

Constant Summary collapse

CONTEXT_LINES =
2
MAX_LINES =
10

Instance Method Summary collapse

Constructor Details

#initialize(source_buffer, location) ⇒ Location

Returns a new instance of Location.



161
162
163
164
# File 'lib/cc/analyzer/formatters/html_formatter.rb', line 161

def initialize(source_buffer, location)
  @source_buffer = source_buffer
  @location = location
end

Instance Method Details

#begin_lineObject



166
167
168
# File 'lib/cc/analyzer/formatters/html_formatter.rb', line 166

def begin_line
  @begin_line ||= line("begin")
end

#codeObject



189
190
191
192
193
194
195
196
197
# File 'lib/cc/analyzer/formatters/html_formatter.rb', line 189

def code
  first_line = start
  last_line = [
    end_line + CONTEXT_LINES,
    begin_line + MAX_LINES + CONTEXT_LINES,
    source_buffer.line_count,
  ].min
  source_buffer.source.lines[(first_line - 1)..(last_line - 1)].join("")
end

#end_lineObject



170
171
172
# File 'lib/cc/analyzer/formatters/html_formatter.rb', line 170

def end_line
  @end_line ||= line("end")
end

#line_offsetObject



185
186
187
# File 'lib/cc/analyzer/formatters/html_formatter.rb', line 185

def line_offset
  start - 1
end

#startObject



181
182
183
# File 'lib/cc/analyzer/formatters/html_formatter.rb', line 181

def start
  [begin_line - CONTEXT_LINES, 1].max
end

#to_sObject



174
175
176
177
178
179
# File 'lib/cc/analyzer/formatters/html_formatter.rb', line 174

def to_s
  [
    begin_line,
    end_line,
  ].uniq.join("-")
end