Class: Epuber::Checker::TextChecker::MatchProblem
- Inherits:
-
Object
- Object
- Epuber::Checker::TextChecker::MatchProblem
- Defined in:
- lib/epuber/checker/text_checker.rb
Instance Method Summary collapse
-
#caret_symbol(indent) ⇒ String
Formats caret symbol with space indent.
-
#caret_symbols(indent, length) ⇒ String
Formats caret symbols for indent and length.
- #formatted_match_line ⇒ Object
-
#initialize(match, message, file_path) ⇒ MatchProblem
constructor
A new instance of MatchProblem.
- #remove_tabs(text) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(match, message, file_path) ⇒ MatchProblem
Returns a new instance of MatchProblem.
17 18 19 20 21 |
# File 'lib/epuber/checker/text_checker.rb', line 17 def initialize(match, , file_path) @match = match @message = @file_path = file_path end |
Instance Method Details
#caret_symbol(indent) ⇒ String
Formats caret symbol with space indent
29 30 31 |
# File 'lib/epuber/checker/text_checker.rb', line 29 def caret_symbol(indent) ' ' * indent + '^' end |
#caret_symbols(indent, length) ⇒ String
Formats caret symbols for indent and length
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/epuber/checker/text_checker.rb', line 40 def caret_symbols(indent, length) start_sign = caret_symbol(indent) end_sign = if length > 1 caret_symbol(length-2) else '' end "#{start_sign}#{end_sign}" end |
#formatted_match_line ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/epuber/checker/text_checker.rb', line 51 def formatted_match_line match_line = @match.matched_string pre_line = @match.pre_match_lines.last || '' pre = match_pre_line = pre_line if remove_tabs(match_pre_line).length > 100 pre = "#{match_pre_line.first(20)}...#{match_pre_line.last(30)}" end pre = remove_tabs(pre) post_line = @match.post_match_lines.first || '' post = if post_line.length > 50 "#{post_line.first(50)}..." else post_line end [pre, match_line, post] end |
#remove_tabs(text) ⇒ Object
73 74 75 |
# File 'lib/epuber/checker/text_checker.rb', line 73 def remove_tabs(text) text.gsub("\t", ' ' * 4) end |
#to_s ⇒ Object
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/epuber/checker/text_checker.rb', line 77 def to_s pre_original = @match.pre_match_lines.last || '' pre, match_text, post = formatted_match_line pointers = caret_symbols(pre.length, match_text.length) %{#{@file_path}:#{@match.line_number} column: #{pre_original.length} --- #{@message} #{pre + match_text.ansi.red + post} #{pointers}} end |