module Mentor::OutputHelper
Public Instance Methods
a_an(word)
click to toggle source
# File lib/helpers/output_helper.rb, line 5 def a_an(word) %w(A E I O U).include?(word[0]) ? 'an' : 'a' end
and_sentence(words)
click to toggle source
# File lib/helpers/output_helper.rb, line 25 def and_sentence(words) words.join(' and ') end
culprit_line()
click to toggle source
# File lib/helpers/output_helper.rb, line 9 def culprit_line lines_from_file[tp.lineno] end
home_to_tilde(path)
click to toggle source
# File lib/helpers/output_helper.rb, line 29 def home_to_tilde(path) path.sub(ENV['HOME'], '~') end
indent_lines(*lines, indent: 2)
click to toggle source
# File lib/helpers/output_helper.rb, line 33 def indent_lines(*lines, indent: 2) lines.flatten! indent.downto(1).each do |number_of_spaces| if lines.all? { |line| line.size + indent * 2 <= terminal_width } return lines.map { |line| ' ' * number_of_spaces + line } end end lines end
lines_from_file()
click to toggle source
# File lib/helpers/output_helper.rb, line 45 def lines_from_file return @lines_from_file if @lines_from_file file = File.new(Mentor.tp.path) @lines_from_file = file.map { |line| [file.lineno, line.chomp] }.to_h end
or_sentence(words)
click to toggle source
# File lib/helpers/output_helper.rb, line 21 def or_sentence(words) words.join(' or ') end
pluralize(word)
click to toggle source
# File lib/helpers/output_helper.rb, line 13 def pluralize(word) word.to_s + (word.to_s == 'Hash' ? 'es' : 's') end
pluralize_words(words)
click to toggle source
# File lib/helpers/output_helper.rb, line 17 def pluralize_words(words) words.map { |word| pluralize word } end
terminal_width()
click to toggle source
# File lib/helpers/output_helper.rb, line 51 def terminal_width `tput cols`.to_i end
valid_var_name()
click to toggle source
# File lib/helpers/output_helper.rb, line 55 def valid_var_name /(@@|@|\$)?[a-zA-Z][a-zA-Z_0-9]*/ end