https://github.com/yegor256/ellipsized
A Ruby function that replaces a piece of text with ellipsis in order to make it fit into certain number of characters
https://github.com/yegor256/ellipsized
ellipsis ruby ruby-gem string-manipulation
Last synced: 12 months ago
JSON representation
A Ruby function that replaces a piece of text with ellipsis in order to make it fit into certain number of characters
- Host: GitHub
- URL: https://github.com/yegor256/ellipsized
- Owner: yegor256
- License: mit
- Created: 2025-05-20T17:54:48.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2025-06-29T04:07:36.000Z (12 months ago)
- Last Synced: 2025-06-29T05:19:14.747Z (12 months ago)
- Topics: ellipsis, ruby, ruby-gem, string-manipulation
- Language: Ruby
- Homepage: https://rubygems.org/gems/ellipsized
- Size: 48.8 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Adds a `.ellipsized` method to `String`
[](https://www.rultor.com/p/yegor256/ellipsized)
[](https://www.jetbrains.com/ruby/)
[](https://github.com/yegor256/ellipsized/actions/workflows/rake.yml)
[](https://www.0pdd.com/p?name=yegor256/ellipsized)
[](https://badge.fury.io/rb/ellipsized)
[](https://codecov.io/github/yegor256/ellipsized?branch=master)
[](https://rubydoc.info/github/yegor256/ellipsized/master/frames)
[](https://hitsofcode.com/view/github/yegor256/ellipsized)
[](https://github.com/yegor256/ellipsized/blob/master/LICENSE.txt)
It makes a string fit into a required length by replacing
part of it in the middle with an [ellipsis]:
```ruby
require 'ellipsized'
puts 'Hello, dear world!'.ellipsized(16)
```
Prints:
```text
Hello, ...world!
```
You can also specify what to use to fill the gap:
```ruby
puts 'How are you doing?'.ellipsized(14, '.. skip ..')
```
Prints:
```text
Ho.. skip ..g?
```
You can also specify alignment:
```ruby
puts 'How are you doing?'.ellipsized(14, '.. skip ..', :left)
```
Prints:
```text
.. skip ..ing?
```
That's it.
## How to contribute
Read
[these guidelines](https://www.yegor256.com/2014/04/15/github-guidelines.html).
Make sure your build is green before you contribute
your pull request. You will need to have
[Ruby](https://www.ruby-lang.org/en/) 3.0+ and
[Bundler](https://bundler.io/) installed. Then run:
```bash
bundle update
bundle exec rake
```
If it's clean and you don't see any error messages, submit your pull request.
[ellipsis]: https://en.wikipedia.org/wiki/Ellipsis