Code Monkey home page Code Monkey logo

ellipsis's Introduction

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.

ellipsis's People

Contributors

learnjin avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.