0.0
No commit activity in last 3 years
No release in over 3 years
Gem to create and manage an array of ranges
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 1.3
>= 0
>= 0
 Project Readme

RangeArray

This is a very simple subclass of the Array class, aimed specifically at supporting Ranges, rather than general objects.

When a new range is added to the array (using the << method), the RangeArray ensures that there are no overlapping ranges, and if necessary, merges any overlapping ranges into a single range.

For example, if the RangeArray holds the ranges (1..10) and (20..30), appending the range (5..25) will merge all ranges into a single range (1..30).

At this stage, only the << has been overridden, so no other methods are checked to guard against non-range members.

Installation

Add this line to your application's Gemfile:

gem 'range_array'

And then execute:

$ bundle

Or install it yourself as:

$ gem install range_array

Usage

In your Gemfile:

gem 'range_array'

Simple example:

require 'range_array'
ra = RangeArray.new
ra << (1..10)  # [(1..10)]
ra << (20..30) # [(1..10), (20..30)]
ra << (5..25)  # [(1..30)]

Also works for dates:

require 'range_array'
require 'date'
ra = RangeArray.new
ra << (Date.parse('2013-01-01') .. Date.parse('2013-05-01'))
ra << (Date.parse('2013-10-01') .. Date.parse('2013-12-31'))
ra << (Date.parse('2013-04-01') .. Date.parse('2013-11-01')) # [('2013-01-01' .. '2013-12-31')]

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request