sixarm_ruby_week 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/CHANGELOG.txt +4 -0
- data/INSTALL.txt +32 -0
- data/LICENSE.txt +25 -0
- data/README.rdoc +31 -0
- data/Rakefile +8 -0
- data/VERSION +1 -0
- data/lib/sixarm_ruby_week.rb +213 -0
- data/test/sixarm_ruby_week_test.rb +137 -0
- data.tar.gz.sig +1 -0
- metadata +94 -0
- metadata.gz.sig +1 -0
data/.gemtest
ADDED
File without changes
|
data/CHANGELOG.txt
ADDED
data/INSTALL.txt
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
|
2
|
+
= SixArm.com Ruby Gem Install
|
3
|
+
|
4
|
+
|
5
|
+
First-time users: add our gem certificate and source.
|
6
|
+
When you do this once, it works for all our gems.
|
7
|
+
|
8
|
+
sudo wget http://sixarm.com/sixarm.pem
|
9
|
+
sudo gem cert --add sixarm.pem
|
10
|
+
sudo gem sources --add http://sixarm.com
|
11
|
+
|
12
|
+
Install the gem with advanced options.
|
13
|
+
|
14
|
+
sudo gem install sixarm_ruby_week --test --trust-policy HighSecurity
|
15
|
+
|
16
|
+
|
17
|
+
== Notes
|
18
|
+
|
19
|
+
Do you have any questions, comments, suggestions, or feedback?
|
20
|
+
Let us know, we're happy to help. Our email is sixarm@sixarm.com
|
21
|
+
|
22
|
+
Do you want to create your own high security gems?
|
23
|
+
Learn how at http://www.rubygems.org/read/chapter/21
|
24
|
+
|
25
|
+
To see your current gem certificate list:
|
26
|
+
|
27
|
+
sudo gem cert --list
|
28
|
+
|
29
|
+
Our cert looks like this:
|
30
|
+
|
31
|
+
/C=US/ST=California/L=San Francisco/O=SixArm/CN=sixarm.com
|
32
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
LICENSE
|
2
|
+
|
3
|
+
You may choose any of these open source licenses:
|
4
|
+
|
5
|
+
- Apache License
|
6
|
+
- BSD License
|
7
|
+
- CreativeCommons License, Non-commercial Share Alike
|
8
|
+
- GNU General Public License Version 2 (GPL 2)
|
9
|
+
- GNU Lesser General Public License (LGPL)
|
10
|
+
- MIT License
|
11
|
+
- Perl Artistic License
|
12
|
+
- Ruby License
|
13
|
+
|
14
|
+
The software is provided "as is", without warranty of any kind,
|
15
|
+
express or implied, including but not limited to the warranties of
|
16
|
+
merchantability, fitness for a particular purpose and noninfringement.
|
17
|
+
|
18
|
+
In no event shall the authors or copyright holders be liable for any
|
19
|
+
claim, damages or other liability, whether in an action of contract,
|
20
|
+
tort or otherwise, arising from, out of or in connection with the
|
21
|
+
software or the use or other dealings in the software.
|
22
|
+
|
23
|
+
This license is for the included software that is created by SixArm;
|
24
|
+
some of the included software may have its own licenses, copyrights,
|
25
|
+
authors, etc. and these do take precedence over the SixArm license.
|
data/README.rdoc
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
= SixArm.com » Ruby » Week model based on Ruby Date
|
2
|
+
|
3
|
+
Author:: Joel Parker Henderson, joel@joelparkerhenderson.com
|
4
|
+
Copyright:: Copyright (c) 2006-2012 Joel Parker Henderson
|
5
|
+
License:: See LICENSE.txt file
|
6
|
+
|
7
|
+
This gem models a week, based on the built-in Ruby Date class.
|
8
|
+
|
9
|
+
== Examples
|
10
|
+
|
11
|
+
week = Week.parse('2012-01-02')
|
12
|
+
week.to_s => '2012-01-02'
|
13
|
+
|
14
|
+
== Example Enumerable
|
15
|
+
|
16
|
+
week.previous.to_s => '2011-12-26'
|
17
|
+
week.next.to_s => '2012-01-16'
|
18
|
+
|
19
|
+
== Example Math
|
20
|
+
|
21
|
+
(week - 3).to_s => '2011-12-12'
|
22
|
+
(week + 3).to_s => '2012-01-24'
|
23
|
+
|
24
|
+
== Example Range Helpers
|
25
|
+
|
26
|
+
week.start_date.to_s => '2012-01-02'
|
27
|
+
week.end_date.to_s => '2012-01-09'
|
28
|
+
week.includes?(Date.parse('2012-01-05')) => true
|
29
|
+
|
30
|
+
|
31
|
+
|
data/Rakefile
ADDED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
@@ -0,0 +1,213 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
=begin rdoc
|
3
|
+
Please see README.rdoc
|
4
|
+
=end
|
5
|
+
|
6
|
+
require 'date'
|
7
|
+
|
8
|
+
|
9
|
+
class Week
|
10
|
+
|
11
|
+
attr :date
|
12
|
+
|
13
|
+
def initialize(date)
|
14
|
+
@date = date
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
# Return date.to_s
|
19
|
+
|
20
|
+
def to_s
|
21
|
+
@date.to_s
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
### Instantiations
|
26
|
+
|
27
|
+
|
28
|
+
# Return the week that starts today
|
29
|
+
|
30
|
+
def self.now
|
31
|
+
Week.new(Date.today)
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
# Parse date text to a week.
|
36
|
+
#
|
37
|
+
# @example
|
38
|
+
# week = Week.parse('2012-01-02')
|
39
|
+
|
40
|
+
def self.parse(date_text)
|
41
|
+
Week.new(Date.parse(date_text))
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
### Comparable
|
46
|
+
|
47
|
+
|
48
|
+
# Return the hash for object comparison.
|
49
|
+
#
|
50
|
+
# This is simply the has of the date, which means
|
51
|
+
# that two week objects created with the same date
|
52
|
+
# will compare equally.
|
53
|
+
|
54
|
+
def hash
|
55
|
+
date.hash
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
# Return week1.date == week2.date
|
60
|
+
|
61
|
+
def ==(other)
|
62
|
+
self.date == other.date
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
# Return week1.date.eql? week2.date
|
67
|
+
|
68
|
+
def eql?(other)
|
69
|
+
self.date == other.date
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
# Return week1.date <=> week2.date
|
74
|
+
|
75
|
+
def <=>(other)
|
76
|
+
return self.date <=> other.date
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
# Return week1.date < week2.date
|
81
|
+
|
82
|
+
def <(other)
|
83
|
+
self.date < other.date
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
# Return week1.date <= week2.date
|
88
|
+
|
89
|
+
def <=(other)
|
90
|
+
self.date <= other.date
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
# Return week1.date > week2.date
|
95
|
+
|
96
|
+
def >(other)
|
97
|
+
self.date > other.date
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
# Return week1.date >= week2.date
|
102
|
+
|
103
|
+
def >=(other)
|
104
|
+
self.date >= other.date
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
### Math
|
109
|
+
|
110
|
+
|
111
|
+
# Addition: week + other => week
|
112
|
+
#
|
113
|
+
# Return a date object pointing other weeks after self.
|
114
|
+
# The other should be a numeric value.
|
115
|
+
#
|
116
|
+
# @example
|
117
|
+
# week = Week.parse('2012-01-02')
|
118
|
+
# week + 3 => three weeks later
|
119
|
+
|
120
|
+
def +(other)
|
121
|
+
if other.is_a? Numeric
|
122
|
+
return Week.new(date + (other.to_i * 7))
|
123
|
+
else
|
124
|
+
raise TypeError
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
|
129
|
+
# Subtraction: week - other => week or integer
|
130
|
+
#
|
131
|
+
# If the other is a numeric value, return a week object pointing other weeks before self.
|
132
|
+
#
|
133
|
+
# If the other is a week object, then return the difference between the two weeks.
|
134
|
+
#
|
135
|
+
# @example
|
136
|
+
# date = date.parse('2012-01-02')
|
137
|
+
# week = Week.new(date)
|
138
|
+
# week - 3 => three weeks earlier
|
139
|
+
#
|
140
|
+
# @example
|
141
|
+
# date = date.parse('2012-01-02')
|
142
|
+
# start_week = Week.new(date)
|
143
|
+
# end_week = Week.new(date + 21)
|
144
|
+
# end_week - start_week => 3
|
145
|
+
|
146
|
+
def -(other)
|
147
|
+
if other.is_a? Numeric
|
148
|
+
return Week.new(date - (other * 7))
|
149
|
+
elsif other.is_a? Week
|
150
|
+
return ((self.date - other.date) / 7).round
|
151
|
+
else
|
152
|
+
raise TypeError
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
|
157
|
+
### Enumerable
|
158
|
+
|
159
|
+
# Return the previous week, i.e. seven day earlier.
|
160
|
+
|
161
|
+
def previous
|
162
|
+
return self - 1
|
163
|
+
end
|
164
|
+
|
165
|
+
|
166
|
+
# Return the next week, i.e. seven day later.
|
167
|
+
|
168
|
+
def next
|
169
|
+
return self + 1
|
170
|
+
end
|
171
|
+
|
172
|
+
|
173
|
+
### Ranges
|
174
|
+
|
175
|
+
|
176
|
+
# Return the start date of this week.
|
177
|
+
# This is the same as week.date.
|
178
|
+
#
|
179
|
+
# @example
|
180
|
+
# week = Week.parse('2012-01-02')
|
181
|
+
# week.start_date.to_s => '2012-01-02'
|
182
|
+
|
183
|
+
def start_date
|
184
|
+
@date
|
185
|
+
end
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
# Return the end date of this week.
|
190
|
+
# This is the same as week.date + 6 days
|
191
|
+
#
|
192
|
+
# @example
|
193
|
+
# week = Week.parse('2012-01-02')
|
194
|
+
# week.end_date.to_s => '2012-01-09'
|
195
|
+
|
196
|
+
def end_date
|
197
|
+
@date + 6
|
198
|
+
end
|
199
|
+
|
200
|
+
|
201
|
+
# Return true iif the week includes the date, i.e. if the date is in start_date..end_date
|
202
|
+
#
|
203
|
+
# @example
|
204
|
+
# week = Week.parse('2012-01-02')
|
205
|
+
# week.includes?(Date.parse('2012-01-05')) => true
|
206
|
+
# week.includes?(Date.parse('2012-01-10')) => false
|
207
|
+
|
208
|
+
def includes?(date)
|
209
|
+
(start_date..end_date).include?(date)
|
210
|
+
end
|
211
|
+
|
212
|
+
|
213
|
+
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'test/unit'
|
3
|
+
require 'simplecov'
|
4
|
+
SimpleCov.start
|
5
|
+
require 'sixarm_ruby_week'
|
6
|
+
|
7
|
+
class WeekTest < Test::Unit::TestCase
|
8
|
+
|
9
|
+
DATE = Date.parse('2012-01-02')
|
10
|
+
WEEK = Week.new(DATE)
|
11
|
+
WEEK_PREV = Week.new(DATE-7)
|
12
|
+
WEEK_NEXT = Week.new(DATE+7)
|
13
|
+
|
14
|
+
def test_initialize
|
15
|
+
assert_equal(WEEK.date.cwyear, 2012)
|
16
|
+
assert_equal(WEEK.date.cweek, 1)
|
17
|
+
assert_equal(WEEK.date.cwday, 1)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_date
|
21
|
+
assert_equal(DATE, WEEK.date)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_to_s
|
25
|
+
assert_equal('2012-01-02', WEEK.to_s)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_now
|
29
|
+
assert_equal(Date.today, Week.now.date)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_parse
|
33
|
+
week = Week.parse('2012-01-02')
|
34
|
+
assert_equal(DATE, week.date)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_hash
|
38
|
+
assert_equal(DATE.hash, WEEK.hash)
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_eq
|
42
|
+
assert(WEEK == Week.new(DATE))
|
43
|
+
assert(!(WEEK == Week.new(DATE+1)))
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_eql
|
47
|
+
assert(WEEK.eql? Week.new(DATE))
|
48
|
+
assert(!(WEEK.eql? Week.new(DATE+1)))
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_compare
|
52
|
+
assert_equal(-1, WEEK <=> WEEK_NEXT)
|
53
|
+
assert_equal( 0, WEEK <=> WEEK)
|
54
|
+
assert_equal( 1, WEEK <=> WEEK_PREV)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_lt
|
58
|
+
assert(!(WEEK < WEEK_PREV))
|
59
|
+
assert(!(WEEK < WEEK))
|
60
|
+
assert(WEEK < WEEK_NEXT)
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_lte
|
64
|
+
assert(!(WEEK <= WEEK_PREV))
|
65
|
+
assert(WEEK <= WEEK)
|
66
|
+
assert(WEEK < WEEK_NEXT)
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_gt
|
70
|
+
assert(WEEK > WEEK_PREV)
|
71
|
+
assert(!(WEEK > WEEK))
|
72
|
+
assert(!(WEEK > WEEK_NEXT))
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_gte
|
76
|
+
assert(WEEK > WEEK_PREV)
|
77
|
+
assert(WEEK >= WEEK)
|
78
|
+
assert(!(WEEK > WEEK_NEXT))
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_plus_with_numeric
|
82
|
+
assert_equal(WEEK_NEXT, WEEK + 1)
|
83
|
+
assert_not_equal(WEEK_NEXT, WEEK + 2)
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_plus_with_bad_type
|
87
|
+
assert_raise TypeError do
|
88
|
+
WEEK + "foo"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_minus_with_numeric
|
93
|
+
assert_equal(WEEK_PREV, WEEK - 1)
|
94
|
+
assert_not_equal(WEEK_PREV, WEEK + 2)
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_minus_with_week
|
98
|
+
assert_equal(1, WEEK - WEEK_PREV)
|
99
|
+
assert_equal(0, WEEK - WEEK)
|
100
|
+
assert_equal(-1, WEEK - WEEK_NEXT)
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_minus_with_bad_type
|
104
|
+
assert_raise TypeError do
|
105
|
+
WEEK - "foo"
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_previous
|
110
|
+
assert_equal(WEEK_PREV, WEEK.previous)
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_next
|
114
|
+
assert_equal(WEEK_NEXT, WEEK.next)
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_start_date
|
118
|
+
assert_equal(DATE, WEEK.start_date)
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_end_date
|
122
|
+
assert_equal(DATE + 6, WEEK.end_date)
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_includes
|
126
|
+
assert(!(WEEK.includes? DATE-1))
|
127
|
+
assert(WEEK.includes? DATE+0)
|
128
|
+
assert(WEEK.includes? DATE+1)
|
129
|
+
assert(WEEK.includes? DATE+2)
|
130
|
+
assert(WEEK.includes? DATE+3)
|
131
|
+
assert(WEEK.includes? DATE+4)
|
132
|
+
assert(WEEK.includes? DATE+5)
|
133
|
+
assert(WEEK.includes? DATE+6)
|
134
|
+
assert(!(WEEK.includes? DATE+7))
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
data.tar.gz.sig
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
M��h�9�l�ź$�-�,�C�V�n�H��u%��܂0�˘��kD��ֺ�A�_�3́-�=>�1����?�R:��:��oЎ����ɸ4�۽�h9ٚWP�ȍ��Z�M�T.E:2by:��
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sixarm_ruby_week
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- SixArm
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain:
|
12
|
+
- ! '-----BEGIN CERTIFICATE-----
|
13
|
+
|
14
|
+
MIIDBDCCAm2gAwIBAgIJAKPwEETU5bHoMA0GCSqGSIb3DQEBBQUAMGAxCzAJBgNV
|
15
|
+
|
16
|
+
BAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1TYW4gRnJhbmNp
|
17
|
+
|
18
|
+
c2NvMQ8wDQYDVQQKEwZTaXhBcm0xEzARBgNVBAMTCnNpeGFybS5jb20wHhcNMTAx
|
19
|
+
|
20
|
+
MjEz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
|
48
|
+
-----END CERTIFICATE-----
|
49
|
+
|
50
|
+
'
|
51
|
+
date: 2012-02-25 00:00:00.000000000 Z
|
52
|
+
dependencies: []
|
53
|
+
description:
|
54
|
+
email: sixarm@sixarm.com
|
55
|
+
executables: []
|
56
|
+
extensions: []
|
57
|
+
extra_rdoc_files: []
|
58
|
+
files:
|
59
|
+
- .gemtest
|
60
|
+
- CHANGELOG.txt
|
61
|
+
- INSTALL.txt
|
62
|
+
- LICENSE.txt
|
63
|
+
- Rakefile
|
64
|
+
- README.rdoc
|
65
|
+
- VERSION
|
66
|
+
- lib/sixarm_ruby_week.rb
|
67
|
+
- test/sixarm_ruby_week_test.rb
|
68
|
+
homepage: http://sixarm.com/
|
69
|
+
licenses: []
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ! '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
requirements: []
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 1.8.11
|
89
|
+
signing_key:
|
90
|
+
specification_version: 3
|
91
|
+
summary: SixArm.com » Ruby » Week is seven days from Monday onward
|
92
|
+
test_files:
|
93
|
+
- test/sixarm_ruby_week_test.rb
|
94
|
+
has_rdoc: true
|
metadata.gz.sig
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
�O<��V��S�39����T��R\���J��(�m�Q��2%-���r����,����T�,rV<�\9`��()��\��-�(�O��r'�#Ik��B�b�H#ѵtE?���諍\!
|