Skip to content

A Ruby function that replaces a piece of text with ellipsis in order to make it fit into certain number of characters

License

Notifications You must be signed in to change notification settings

yegor256/ellipsized

Repository files navigation

Adds a .ellipsized method to String

DevOps By Rultor.com We recommend RubyMine

rake PDD status Gem Version Test Coverage Yard Docs Hits-of-Code License

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.

About

A Ruby function that replaces a piece of text with ellipsis in order to make it fit into certain number of characters

Topics

Resources

License

Stars

Watchers

Forks

Contributors 3

  •  
  •  
  •  

Languages