Skip to content

learnjin/ellipsis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ellipsis

By making use of an ellipsis or similar symbols the representation of a list of elements can be abbreviated. This can be helpful in situtations where character space is limited, and at the same time may be more aesthetically pleasing.

Installation

Installation as usual:

gem install ellipsis

Usage and Examples

After you require the gem with

require 'ellipsis'

The array class is extended with the following two methods that are similar to the to_sentence method in Rails.

to_abbr_series

This method assumes that the elements represent a sorted list; Using the method displays an ellipsis. For example:

[1,2,3,4,5].to_abbr_series    # => "1, 2, ..., 5"

to_abbr_set

This method summarizes consecutive subsets in with dash. See the following example:

[1,2,3, 5,6].to_abbr_set      # => "1-3, 5, 6"

So far the notion of consecutive refers to integer successors. Thus the array needs to be an integer array. If you don’t want integers in the actual string representation you can pass an additional block that will convert an integer to a custom string representation:

WEEKDAYS = ['mon', 'tue', 'wed','thu', 'fri', 'sat', 'sun']
days = [1,2,3,5,6]

days.to_abbr_set {|e| WEEKDAYS[e] }    # =>  'mon-wed, fri, sat'

Outlook

  • refactor unit tests

  • Implement options similar to the to_sentence method in Rails.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages