Sha256: 6e16aacc5ec8eaf7ce184b0d9311c698e311c1c58f08c4ee04755c72d3e6018d

Contents?: true

Size: 638 Bytes

Versions: 5

Compression:

Stored size: 638 Bytes

Contents

module ErrorHighlight
  class DefaultFormatter
    def self.message_for(spot)
      # currently only a one-line code snippet is supported
      if spot[:first_lineno] == spot[:last_lineno]
        indent = spot[:snippet][0...spot[:first_column]].gsub(/[^\t]/, " ")
        marker = indent + "^" * (spot[:last_column] - spot[:first_column])

        "\n\n#{ spot[:snippet] }#{ marker }"
      else
        ""
      end
    end
  end

  def self.formatter
    Ractor.current[:__error_highlight_formatter__] || DefaultFormatter
  end

  def self.formatter=(formatter)
    Ractor.current[:__error_highlight_formatter__] = formatter
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
error_highlight-0.6.0 lib/error_highlight/formatter.rb
error_highlight-0.5.1 lib/error_highlight/formatter.rb
error_highlight-0.5.0 lib/error_highlight/formatter.rb
error_highlight-0.4.0 lib/error_highlight/formatter.rb
error_highlight-0.3.0 lib/error_highlight/formatter.rb