class RandomWords::Generator

def handle_overflow(config)

def handle_overflow(config)
  space = config.whitespace ? ' ' : ''
  needed = config.max - config.result.compress.length - space.length
  config.min = config.max if config.min > config.max
  if needed > 1
    options = nouns_of_length(needed)
    return "#{config.result}#{space}#{options.sample}".compress unless options.empty?
  end
  if config.whole_words
    return characters(config.min, config.max, whole_words: config.whole_words, whitespace: config.whitespace,
                                              dead_switch: config.dead_switch + 1)
  end
  truncated = config.new_result.compress[0...config.max]
  truncated.strip if truncated.strip.length.between?(config.min, config.max)
end