class Mentor::LinesOfCode
Public Instance Methods
lines()
click to toggle source
# File lib/sections/lines_of_codes.rb, line 7 def lines indent_lines(lines_of_code_from_method_or_file, indent: 4) end
Private Instance Methods
calling_method_can_be_obtained?()
click to toggle source
# File lib/sections/lines_of_codes.rb, line 27 def calling_method_can_be_obtained? calling_method != '<main>' end
first_line_at_start_of_file?()
click to toggle source
# File lib/sections/lines_of_codes.rb, line 48 def first_line_at_start_of_file? @first_lineno == 1 end
first_line_empty?()
click to toggle source
# File lib/sections/lines_of_codes.rb, line 52 def first_line_empty? lines_from_file[@first_lineno].empty? end
last_line_at_end_of_file?()
click to toggle source
# File lib/sections/lines_of_codes.rb, line 60 def last_line_at_end_of_file? @last_lineno == lines_from_file.size end
last_line_empty?()
click to toggle source
# File lib/sections/lines_of_codes.rb, line 64 def last_line_empty? lines_from_file[@last_lineno].empty? end
line_prior_to_first_line_ends?()
click to toggle source
# File lib/sections/lines_of_codes.rb, line 56 def line_prior_to_first_line_ends? lines_from_file[@first_lineno - 1]['end'] end
lines_of_code_from_method_or_file()
click to toggle source
# File lib/sections/lines_of_codes.rb, line 13 def lines_of_code_from_method_or_file if calling_method_can_be_obtained? set_first_and_last_from_method else set_first_and_last_from_file end lineno_max_length = "=> #{@last_lineno}".length (@first_lineno..@last_lineno).map do |lineno| LineOfCode.new(lineno, lines_from_file[lineno], lineno_max_length) end end
set_first_and_last_from_file()
click to toggle source
# File lib/sections/lines_of_codes.rb, line 37 def set_first_and_last_from_file @first_lineno = Mentor.tp.lineno @first_lineno -= 1 until first_line_at_start_of_file? || first_line_empty? || line_prior_to_first_line_ends? @last_lineno = Mentor.tp.lineno @last_lineno += 1 until last_line_at_end_of_file? || last_line_empty? end
set_first_and_last_from_method()
click to toggle source
# File lib/sections/lines_of_codes.rb, line 31 def set_first_and_last_from_method method_text = Pry::Method.from_str("#{Mentor.tp.defined_class}##{calling_method}").source.split("\n") @first_lineno = lines_from_file.select { |_lineno, line| line["def #{calling_method}"] }.sort.last.first @last_lineno = @first_lineno + method_text.size - 1 end