Adds a .ellipsized
method to String
It makes a string fit into a required length by replacing part of it in the middle with an ellipsis:
require 'ellipsized'
puts 'Hello, dear world!'.ellipsized(16)
Prints:
Hello, ...world!
You can also specify what to use to fill the gap:
puts 'How are you doing?'.ellipsized(14, '.. skip ..')
Prints:
Ho.. skip ..g?
You can also specify alignment:
puts 'How are you doing?'.ellipsized(14, '.. skip ..', :left)
Prints:
.. skip ..ing?
That's it.
How to contribute
Read these guidelines. Make sure your build is green before you contribute your pull request. You will need to have Ruby 3.0+ and Bundler installed. Then run:
bundle update
bundle exec rake
If it's clean and you don't see any error messages, submit your pull request.