Module: YARD::Spellcheck::Printer
- Included in:
- CLI::Spellcheck
- Defined in:
- lib/yard/spellcheck/printer.rb
Overview
Provides methods for printing the typos found in YARD Documentation.
Constant Summary collapse
- HIGHLIGHT =
Highlights text
"\e[31m\e[4m"
- UNHIGHLIGHT =
Unhighlights text
"\e[0m"
Instance Method Summary collapse
-
#print_stats(checker) ⇒ Object
Prints statistics gathered by the spellchecker.
-
#print_text(line_number, text, typos) ⇒ Object
Prints text containing typos.
-
#print_typos(element, typos) ⇒ Object
Prints typos in a YARD Documentation element.
Instance Method Details
#print_stats(checker) ⇒ Object
Prints statistics gathered by the spellchecker.
82 83 84 85 86 87 88 |
# File 'lib/yard/spellcheck/printer.rb', line 82 def print_stats(checker) stats = checker.misspelled.sort_by { |word,count| -count } stats.each_with_index do |(word,count),index| puts " #{index + 1}. #{word} (#{count})" end end |
#print_text(line_number, text, typos) ⇒ Object
Prints text containing typos.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/yard/spellcheck/printer.rb', line 55 def print_text(line_number,text,typos) # highlight the typos highlighted = text.gsub(Checker::WORD_REGEXP) do |word| if typos.include?(word) "#{HIGHLIGHT}#{word}#{UNHIGHLIGHT}" else word end end puts '' # print the lines highlighted.each_line do |line| puts " #{line_number} #{line}" line_number += 1 end puts '' end |
#print_typos(element, typos) ⇒ Object
Prints typos in a YARD Documentation element.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/yard/spellcheck/printer.rb', line 24 def print_typos(element,typos) case element when YARD::Docstring line = if element.line_range element.line_range.first else 1 end puts "Typos in #{element.object} (#{element.object.file}:#{line})" print_text line, element, typos when YARD::Tags::Tag puts "Typos in @#{element.tag_name} #{element.name} (#{element.object.file}:#{element.object.line})" print_text element.object.line, element.text, typos end end |