diff options
Diffstat (limited to 'lib/error_highlight/formatter.rb')
-rw-r--r-- | lib/error_highlight/formatter.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/error_highlight/formatter.rb b/lib/error_highlight/formatter.rb new file mode 100644 index 0000000000..a3d6510dc2 --- /dev/null +++ b/lib/error_highlight/formatter.rb @@ -0,0 +1,24 @@ +module ErrorHighlight + class DefaultFormatter + def message_for(spot) + # currently only a one-line code snippet is supported + if spot[:first_lineno] == spot[:last_lineno] + marker = " " * spot[:first_column] + "^" * (spot[:last_column] - spot[:first_column]) + + "\n\n#{ spot[:snippet] }#{ marker }" + else + "" + end + end + end + + def self.formatter + @@formatter + end + + def self.formatter=(formatter) + @@formatter = formatter + end + + self.formatter = DefaultFormatter.new +end |