Module: JsonSchema::ErrorFormatter

Defined in:
lib/json_schema/schema_error.rb

Class Method Summary collapse

Class Method Details

.to_list(list) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/json_schema/schema_error.rb', line 39

def to_list(list)
  words_connector     = ', '
  two_words_connector = ' or '
  last_word_connector = ', or '

  length = list.length
  joined_list = case length
                when 1
                  list[0]
                when 2
                  "#{list[0]}#{two_words_connector}#{list[1]}"
                 else
                  "#{list[0...-1].join(words_connector)}#{last_word_connector}#{list[-1]}"
                end

  if joined_list[0] =~ /^[aeiou]/
    "an #{joined_list}"
  else
    "a #{joined_list}"
  end
end