module ErrorsToSentences

Constants

VERSION

Public Instance Methods

to_sentences() click to toggle source
# File lib/errors_to_sentences.rb, line 5
def to_sentences
  sentences = []

  messages.each do |attr, msgs|
    if msgs.size > 1
      sentences << generate_sentence(attr, msgs.dup)
    else
      sentences += full_messages_for(attr)
    end
  end

  sentences
end

Private Instance Methods

generate_sentence(attr, msgs) click to toggle source
# File lib/errors_to_sentences.rb, line 21
def generate_sentence(attr, msgs)
  last_msg = msgs.slice!(-1)
  "#{attr} #{msgs.join(', ')} and #{last_msg}".humanize
end