Module: Mentor::OutputHelper
- Included in:
- Outputs
- Defined in:
- lib/helpers/output_helper.rb
Instance Method Summary collapse
- #home_to_tilde(path) ⇒ Object
- #indent_lines(*lines, indent: 2) ⇒ Object
- #lines_from_file ⇒ Object
- #terminal_width ⇒ Object
- #valid_var_name ⇒ Object
Instance Method Details
#home_to_tilde(path) ⇒ Object
5 6 7 |
# File 'lib/helpers/output_helper.rb', line 5 def home_to_tilde(path) path.sub(ENV['HOME'], '~') end |
#indent_lines(*lines, indent: 2) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/helpers/output_helper.rb', line 9 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 ⇒ Object
21 22 23 24 25 |
# File 'lib/helpers/output_helper.rb', line 21 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 |
#terminal_width ⇒ Object
27 28 29 |
# File 'lib/helpers/output_helper.rb', line 27 def terminal_width `tput cols`.to_i end |
#valid_var_name ⇒ Object
31 32 33 |
# File 'lib/helpers/output_helper.rb', line 31 def valid_var_name /(@@|@|\$)?[a-zA-Z][a-zA-Z_0-9]*/ end |