Project

ice_t

0.0
No commit activity in last 3 years
No release in over 3 years
IceT is a ruby library for handling repeated events
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 1.3
>= 0
~> 2.13

Runtime

 Project Readme

IceT

Gem Version Code Climate Build Status Coverage Status

IceT is a ruby library for handling repeated events.

Installation

Add this line to your application's Gemfile:

gem 'ice_t'

And then execute:

$ bundle

Or install it yourself as:

$ gem install ice_t

Usage

Creating rules

rule = IceT::Rule::Secondly.new(42)  # => every 42 seconds
rule = IceT::Rule::Minutely.new(42)  # => every 42 minutes
rule = IceT::Rule::Hourly.new(42)    # => every 42 hours
rule = IceT::Rule::Daily.new(42)     # => every 42 days
rule = IceT::Rule::Weekly.new(42)    # => every 42 weeks
rule = IceT::Rule::Monthly.new(42)   # => every 42 months
rule = IceT::Rule::Yearly.new(42)    # => every 42 years
rule = IceT::Rule::Secondly.new      # => every second

Rule in words (i18n)

# I18n.locale = :en
rule = IceT::Rule::Daily.new(14)
rule.to_s # => "every 14 days"

# I18n.locale = :de
rule = IceT::Rule::Daily.new(14)
rule.to_s # => "alle 14 Tage"

Get time occurrences

rule.occurrences(2.days.ago, Time.now) # => Array of times

IceT::Rule::Daily.new(14).occurrences(1.year.ago, Time.now).first(5)

Persistence

Store and restore the rule:

# JSON
rule = IceT::Rule::Daily.new(42)
json = rule.to_json
restored = IceT::Rule::Base.from_json(json)

# YAML
rule = IceT::Rule::Daily.new(42)
yaml = rule.to_yaml
restored = IceT::Rule::Base.from_yaml(yaml)

# Hash
rule = IceT::Rule::Daily.new(42)
hash = rule.to_hash
restored = IceT::Rule::Base.from_hash(hash)

Comparison and sorting

IceT::Rule::Daily.new(1) < IceT::Rule::Monthly.new(1) # => true
# compare different type of rules

minutely = IceT::Rule::Minutely.new(1)
hourly   = IceT::Rule::Hourly.new(1)
daily    = IceT::Rule::Daily.new(1)

hourly.between?(minutely, daily) # => true
minutely.between?(hourly, daily) # => false


# compare same type of rules

r1 = IceT::Rule::Daily.new(1)
r2 = IceT::Rule::Daily.new(2)
r3 = IceT::Rule::Daily.new(3)

r2.between?(r1, r2)	# => true
r1.between?(r2, r3)	# => false

# sort these rules

[r2,r1,r3].sort.collect(&:interval) # => [1, 2, 3]

License

This software is released under the MIT License.

Copyright © 2013-2014 Christian Nennemann (christian.nennemann[at]gmail[dot]com)

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.