SixArm.com » Ruby »
Week model based on Ruby Date

Introduction

This gem models a week, based on the built-in Ruby Date class.

For docs go to http://sixarm.com/sixarm_ruby_week/doc

Want to help? We're happy to get pull requests.

Quickstart

Install:

gem install sixarm_ruby_week

Bundler:

gem "sixarm_ruby_week", "=1.1.6"

Require:

require "sixarm_ruby_week"

High Security (Optional)

To enable high security for all our gems:

wget http://sixarm.com/sixarm.pem
gem cert --add sixarm.pem
gem sources --add http://sixarm.com

To install with high security:

gem install sixarm_ruby_week --test --trust-policy HighSecurity

Examples

Create:

date = Date.parse('2012-01-02')
week = Week.new(date)
week.to_s => '2012-01-02'

Parse:

week = Week.parse('2012-01-02')
week => 2012-01-02

Enumerable:

week.previous => 2011-12-26
week.next => 2012-01-16

Math:

week - 3 => 2011-12-12
week + 3 => 2012-01-24

Start & End Dates:

week.start_date => 2012-01-02
week.end_date => 2012-01-08

Range:

week.date_range => Range(2012-01-02..2012-01-08)

Collection:

date = Date.parse('2012-01-02')
week.include?(date) => true
week.include?(date+7) => false

Changes

License

You may choose any of these open source licenses:

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.

This license is for the included software that is created by SixArm; some of the included software may have its own licenses, copyrights, authors, etc. and these do take precedence over the SixArm license.

Copyright (c) 2013 Joel Parker Henderson