month 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3f998e2e63d6369b8d84bfbfa5702e905ea7a902
4
- data.tar.gz: eb30605ca6b103a606a74fe833f191d24847c37d
3
+ metadata.gz: 99d3a1f9ba6751770d9a06df16bd73ee776a8726
4
+ data.tar.gz: 2939e754f6952365f4874ecf4cd6ae262975a723
5
5
  SHA512:
6
- metadata.gz: 8de438f976fd1e79aa70c61bc900d99658ba70abaf59e254b37e486bfcceb7b504376bf373a2a2679315a06ef694ab15f69e5168e2aa9a16ab98417c7e8288ed
7
- data.tar.gz: dba1269a852a8d2a1974a931fd79f03d16dcb94ac9eb3d68b2d9e7ef54b6058b6b227f27c47af7b6a7311943f06e2e6cec993929fa83377517bab63360f18aa5
6
+ metadata.gz: c2e439bbb93bc6b10b0a7a0f0ead067c366660ecaa884c3a2eda73681f1ffa2032600b1964e6cc6fdb75b266f05d2065b7ab6f5a1e723de4179af7a4c82b8f11
7
+ data.tar.gz: 38a4336b1e7c8ad7c258241379a174e4b9538dd76b826e0c1399efbf8e0db7fb00acf9080875f12383e9445b6665f30c3edc07d4fec4b2fb5837981e21a1e70e
@@ -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
@@ -2,7 +2,7 @@ month
2
2
  =====
3
3
 
4
4
 
5
- A little library for working with months.
5
+ A little Ruby library for working with months.
6
6
 
7
7
 
8
8
  Installation
@@ -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
- until month > limit
79
- yield month
80
+ if step > 0
81
+ until month > limit
82
+ yield month
80
83
 
81
- month = month.succ
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
 
@@ -1,13 +1,14 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'month'
3
- s.version = '1.1.0'
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')
@@ -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.1.0
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: 2014-09-19 00:00:00.000000000 Z
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: []