month 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +22 -0
- data/README.md +1 -1
- data/lib/month.rb +23 -5
- data/month.gemspec +4 -3
- data/spec/month_spec.rb +60 -0
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99d3a1f9ba6751770d9a06df16bd73ee776a8726
|
4
|
+
data.tar.gz: 2939e754f6952365f4874ecf4cd6ae262975a723
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2e439bbb93bc6b10b0a7a0f0ead067c366660ecaa884c3a2eda73681f1ffa2032600b1964e6cc6fdb75b266f05d2065b7ab6f5a1e723de4179af7a4c82b8f11
|
7
|
+
data.tar.gz: 38a4336b1e7c8ad7c258241379a174e4b9538dd76b826e0c1399efbf8e0db7fb00acf9080875f12383e9445b6665f30c3edc07d4fec4b2fb5837981e21a1e70e
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright the authors and contributors. All rights reserved.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following
|
10
|
+
conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
data/lib/month.rb
CHANGED
@@ -68,20 +68,38 @@ class Month
|
|
68
68
|
|
69
69
|
alias_method :succ, :next
|
70
70
|
|
71
|
-
def step(limit)
|
71
|
+
def step(limit, step = 1)
|
72
|
+
raise ArgumentError if step.zero?
|
73
|
+
|
72
74
|
unless block_given?
|
73
|
-
return enum_for(:step, limit)
|
75
|
+
return enum_for(:step, limit, step)
|
74
76
|
end
|
75
77
|
|
76
78
|
month = self
|
77
79
|
|
78
|
-
|
79
|
-
|
80
|
+
if step > 0
|
81
|
+
until month > limit
|
82
|
+
yield month
|
80
83
|
|
81
|
-
|
84
|
+
month += step
|
85
|
+
end
|
86
|
+
else
|
87
|
+
until month < limit
|
88
|
+
yield month
|
89
|
+
|
90
|
+
month += step
|
91
|
+
end
|
82
92
|
end
|
83
93
|
end
|
84
94
|
|
95
|
+
def upto(max, &block)
|
96
|
+
step(max, 1, &block)
|
97
|
+
end
|
98
|
+
|
99
|
+
def downto(min, &block)
|
100
|
+
step(min, -1, &block)
|
101
|
+
end
|
102
|
+
|
85
103
|
def +(number)
|
86
104
|
a, b = (@number - 1 + number).divmod(12)
|
87
105
|
|
data/month.gemspec
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'month'
|
3
|
-
s.version = '1.
|
3
|
+
s.version = '1.2.0'
|
4
|
+
s.license = 'MIT'
|
4
5
|
s.platform = Gem::Platform::RUBY
|
5
6
|
s.authors = ['Tim Craft']
|
6
7
|
s.email = ['mail@timcraft.com']
|
7
8
|
s.homepage = 'http://github.com/timcraft/month'
|
8
|
-
s.description = 'A little library for working with months'
|
9
|
+
s.description = 'A little Ruby library for working with months'
|
9
10
|
s.summary = 'See description'
|
10
|
-
s.files = Dir.glob('{lib,spec}/**/*') + %w(README.md month.gemspec)
|
11
|
+
s.files = Dir.glob('{lib,spec}/**/*') + %w(LICENSE.txt README.md month.gemspec)
|
11
12
|
s.required_ruby_version = '>= 1.9.3'
|
12
13
|
s.add_development_dependency('rake', '~> 10.0')
|
13
14
|
s.add_development_dependency('minitest', '~> 5.0')
|
data/spec/month_spec.rb
CHANGED
@@ -109,6 +109,66 @@ describe 'Month' do
|
|
109
109
|
months.next.must_equal(Month.new(2014, 2))
|
110
110
|
months.next.must_equal(Month.new(2014, 3))
|
111
111
|
end
|
112
|
+
|
113
|
+
it 'raises an exception when the given step argument is zero' do
|
114
|
+
proc { Month.new(2014, 1).step(Month.new(2014, 3), 0) }.must_raise(ArgumentError)
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'increases by the given number of months if the step argument is positive' do
|
118
|
+
months = []
|
119
|
+
|
120
|
+
Month.new(2014, 1).step(Month.new(2014, 3), 2) { |month| months << month }
|
121
|
+
|
122
|
+
months.must_equal([Month.new(2014, 1), Month.new(2014, 3)])
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'decreases by the given number of months if the step argument is negative' do
|
126
|
+
months = []
|
127
|
+
|
128
|
+
Month.new(2014, 3).step(Month.new(2014, 1), -1) { |month| months << month }
|
129
|
+
|
130
|
+
months.must_equal([Month.new(2014, 3), Month.new(2014, 2), Month.new(2014, 1)])
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe 'upto method' do
|
135
|
+
it 'calls the block for every month until the given limit' do
|
136
|
+
months = []
|
137
|
+
|
138
|
+
Month.new(2014, 1).upto(Month.new(2014, 3)) { |month| months << month }
|
139
|
+
|
140
|
+
months.must_equal([Month.new(2014, 1), Month.new(2014, 2), Month.new(2014, 3)])
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'returns an enumerator if no block was given' do
|
144
|
+
months = Month.new(2014, 1).upto(Month.new(2014, 3))
|
145
|
+
|
146
|
+
months.must_be_instance_of(Enumerator)
|
147
|
+
|
148
|
+
months.next.must_equal(Month.new(2014, 1))
|
149
|
+
months.next.must_equal(Month.new(2014, 2))
|
150
|
+
months.next.must_equal(Month.new(2014, 3))
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
describe 'downto method' do
|
155
|
+
it 'calls the block for every month until the given limit' do
|
156
|
+
months = []
|
157
|
+
|
158
|
+
Month.new(2014, 3).downto(Month.new(2014, 1)) { |month| months << month }
|
159
|
+
|
160
|
+
months.must_equal([Month.new(2014, 3), Month.new(2014, 2), Month.new(2014, 1)])
|
161
|
+
end
|
162
|
+
|
163
|
+
it 'returns an enumerator if no block was given' do
|
164
|
+
months = Month.new(2014, 3).downto(Month.new(2014, 1))
|
165
|
+
|
166
|
+
months.must_be_instance_of(Enumerator)
|
167
|
+
|
168
|
+
months.next.must_equal(Month.new(2014, 3))
|
169
|
+
months.next.must_equal(Month.new(2014, 2))
|
170
|
+
months.next.must_equal(Month.new(2014, 1))
|
171
|
+
end
|
112
172
|
end
|
113
173
|
|
114
174
|
describe 'addition' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: month
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Craft
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-06-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -38,19 +38,21 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '5.0'
|
41
|
-
description: A little library for working with months
|
41
|
+
description: A little Ruby library for working with months
|
42
42
|
email:
|
43
43
|
- mail@timcraft.com
|
44
44
|
executables: []
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
|
+
- LICENSE.txt
|
48
49
|
- README.md
|
49
50
|
- lib/month.rb
|
50
51
|
- month.gemspec
|
51
52
|
- spec/month_spec.rb
|
52
53
|
homepage: http://github.com/timcraft/month
|
53
|
-
licenses:
|
54
|
+
licenses:
|
55
|
+
- MIT
|
54
56
|
metadata: {}
|
55
57
|
post_install_message:
|
56
58
|
rdoc_options: []
|