class I18n::Hygiene::ErrorMessageBuilder

Constants

LEFT_PAD
TRUNCATE_LIMIT

Public Class Methods

new() click to toggle source
# File lib/i18n/hygiene/error_message_builder.rb, line 9
def initialize
  @title = "Unspecified Error"
  @key = "unknown_key"
  @locale = nil
  @translation = nil
  @location = nil
end

Public Instance Methods

create() click to toggle source
# File lib/i18n/hygiene/error_message_builder.rb, line 42
def create
  s = StringIO.new
  s << "\n"
  s << Rainbow("i18n-hygiene/#{@title}:").red
  s << "\n"
  s << LEFT_PAD

  if @locale
    s << "#{@locale}."
  end

  s << @key

  if @translation
    s << ": "
    s << Rainbow("\"#{truncated_translation}\"").yellow
  end

  if @expected
    s << "\n"
    s << LEFT_PAD * 2
    s << "Expected: "
    s << Rainbow(@expected).color(:orange)
  end

  s << "\n"
  s.string
end
expected(expected) click to toggle source
# File lib/i18n/hygiene/error_message_builder.rb, line 32
def expected(expected)
  @expected = expected
  self
end
key(key) click to toggle source
# File lib/i18n/hygiene/error_message_builder.rb, line 27
def key(key)
  @key = key
  self
end
locale(locale) click to toggle source
# File lib/i18n/hygiene/error_message_builder.rb, line 22
def locale(locale)
  @locale = locale
  self
end
title(title) click to toggle source
# File lib/i18n/hygiene/error_message_builder.rb, line 17
def title(title)
  @title = title
  self
end
translation(translation) click to toggle source
# File lib/i18n/hygiene/error_message_builder.rb, line 37
def translation(translation)
  @translation = translation
  self
end

Private Instance Methods

truncated_translation() click to toggle source
# File lib/i18n/hygiene/error_message_builder.rb, line 73
def truncated_translation
  if @translation.length > TRUNCATE_LIMIT
    @translation[0..TRUNCATE_LIMIT] + "..."
  else
    @translation
  end
end