Class: I18n::Hygiene::ErrorMessageBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/i18n/hygiene/error_message_builder.rb

Constant Summary collapse

LEFT_PAD =
" " * 2
TRUNCATE_LIMIT =
48

Instance Method Summary collapse

Constructor Details

#initializeErrorMessageBuilder

Returns a new instance of ErrorMessageBuilder.



9
10
11
12
13
14
15
# 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

Instance Method Details

#createObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# 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) ⇒ Object



32
33
34
35
# File 'lib/i18n/hygiene/error_message_builder.rb', line 32

def expected(expected)
  @expected = expected
  self
end

#key(key) ⇒ Object



27
28
29
30
# File 'lib/i18n/hygiene/error_message_builder.rb', line 27

def key(key)
  @key = key
  self
end

#locale(locale) ⇒ Object



22
23
24
25
# File 'lib/i18n/hygiene/error_message_builder.rb', line 22

def locale(locale)
  @locale = locale
  self
end

#title(title) ⇒ Object



17
18
19
20
# File 'lib/i18n/hygiene/error_message_builder.rb', line 17

def title(title)
  @title = title
  self
end

#translation(translation) ⇒ Object



37
38
39
40
# File 'lib/i18n/hygiene/error_message_builder.rb', line 37

def translation(translation)
  @translation = translation
  self
end