month 1.5.0 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4009cafb1322ac57f543f1890b413d8082e504720535272ea0de0fb73d82c184
4
- data.tar.gz: fdc90cf876afdc7113d69c80fa1dad52a8d54a97d391ce75b3a500fc82e185a7
3
+ metadata.gz: 1a6feb44a5e36d189f65a6a36a07614431c718f31b894624abf1c0205d3e8728
4
+ data.tar.gz: 8da0fe2b68de33fd429a78c6115b37950c6e78c7facbdffbfd73397450c3ded4
5
5
  SHA512:
6
- metadata.gz: 2c1b9f286ac469bfe6b2d1281a07085ca79e5305ed3ca22c39f7545c10ca0caae84b888a31be84dc75e9e823290ef847635d1c0ef1ef2b5c28055b8b68a4206e
7
- data.tar.gz: b90587bf792e723dc9b59ef8814ffc6165e251c2da8afe596075f0667208781042c140f230707470df6fbdc2cdb3938ae7e426e7a869d206fcb43cd0f846bd1a
6
+ metadata.gz: 4b306459da507afde4a3b43894f04c09618414a62d4150dc3b9674dcd5634bd28ca92fe43911c55ca030615ec38964533d47e1d5debe5109f4503be6ea9026f3
7
+ data.tar.gz: f6e32498fd1528a6926a07e17b3c9d6b515aa98593ac9be3e35909fb981d247983b5bc5bbbb8aeeb1a5113593f7898f7a9c7ff45bd0cfffaa11fdd3bf1bcaa71
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014-2019 TIMCRAFT
1
+ Copyright (c) 2014-2020 TIMCRAFT
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person
4
4
  obtaining a copy of this software and associated documentation
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # month
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/month.svg)](https://badge.fury.io/rb/month) [![Build Status](https://api.travis-ci.org/timcraft/month.svg?branch=master)](https://travis-ci.org/timcraft/month)
3
+ ![Gem Version](https://badge.fury.io/rb/month.svg)
4
+ ![Build Status](https://github.com/readysteady/month/workflows/Test/badge.svg)
4
5
 
5
6
 
6
7
  A little Ruby library for working with months.
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'date'
2
3
 
3
4
  class Month
@@ -28,10 +29,14 @@ class Month
28
29
 
29
30
  attr_reader :year, :number
30
31
 
32
+ alias_method :month, :number
33
+
31
34
  def to_s
32
35
  "#@year-#{@number.to_s.rjust(2, '0')}"
33
36
  end
34
37
 
38
+ alias_method :iso8601, :to_s
39
+
35
40
  def name
36
41
  NAMES.fetch(@number)
37
42
  end
@@ -153,11 +158,17 @@ class Month
153
158
  end
154
159
  end
155
160
 
156
- def Month.parse(string)
157
- if string =~ /\A(\d{4})-(\d{2})\z/
158
- Month.new($1.to_i, $2.to_i)
159
- else
160
- raise ArgumentError, 'invalid month'
161
+ class Month
162
+ REGEXP = /\A(\d{4})-(\d{2})\z/
163
+
164
+ private_constant :REGEXP
165
+
166
+ def self.parse(string)
167
+ if string =~ REGEXP
168
+ Month.new($1.to_i, $2.to_i)
169
+ else
170
+ raise ArgumentError, 'invalid month'
171
+ end
161
172
  end
162
173
  end
163
174
 
@@ -1,16 +1,20 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'month'
3
- s.version = '1.5.0'
3
+ s.version = '1.6.0'
4
4
  s.license = 'MIT'
5
5
  s.platform = Gem::Platform::RUBY
6
6
  s.authors = ['Tim Craft']
7
7
  s.email = ['mail@timcraft.com']
8
- s.homepage = 'https://github.com/timcraft/month'
8
+ s.homepage = 'https://github.com/readysteady/month'
9
9
  s.description = 'A little Ruby library for working with months'
10
10
  s.summary = 'See description'
11
- s.files = Dir.glob('{lib,spec}/**/*') + %w(LICENSE.txt README.md month.gemspec)
11
+ s.files = Dir.glob('lib/**/*.rb') + %w(LICENSE.txt README.md month.gemspec)
12
12
  s.required_ruby_version = '>= 1.9.3'
13
- s.add_development_dependency('rake', '~> 12')
14
- s.add_development_dependency('minitest', '~> 5')
15
13
  s.require_path = 'lib'
14
+ s.metadata = {
15
+ 'homepage' => 'https://github.com/readysteady/month',
16
+ 'source_code_uri' => 'https://github.com/readysteady/month',
17
+ 'bug_tracker_uri' => 'https://github.com/readysteady/month/issues',
18
+ 'changelog_uri' => 'https://github.com/readysteady/month/blob/master/CHANGES.md'
19
+ }
16
20
  end
metadata CHANGED
@@ -1,43 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: month
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.6.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: 2019-01-16 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rake
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '12'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '12'
27
- - !ruby/object:Gem::Dependency
28
- name: minitest
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '5'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '5'
11
+ date: 2020-04-27 00:00:00.000000000 Z
12
+ dependencies: []
41
13
  description: A little Ruby library for working with months
42
14
  email:
43
15
  - mail@timcraft.com
@@ -49,11 +21,14 @@ files:
49
21
  - README.md
50
22
  - lib/month.rb
51
23
  - month.gemspec
52
- - spec/month_spec.rb
53
- homepage: https://github.com/timcraft/month
24
+ homepage: https://github.com/readysteady/month
54
25
  licenses:
55
26
  - MIT
56
- metadata: {}
27
+ metadata:
28
+ homepage: https://github.com/readysteady/month
29
+ source_code_uri: https://github.com/readysteady/month
30
+ bug_tracker_uri: https://github.com/readysteady/month/issues
31
+ changelog_uri: https://github.com/readysteady/month/blob/master/CHANGES.md
57
32
  post_install_message:
58
33
  rdoc_options: []
59
34
  require_paths:
@@ -69,7 +44,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
44
  - !ruby/object:Gem::Version
70
45
  version: '0'
71
46
  requirements: []
72
- rubygems_version: 3.0.1
47
+ rubygems_version: 3.1.2
73
48
  signing_key:
74
49
  specification_version: 4
75
50
  summary: See description
@@ -1,353 +0,0 @@
1
- require 'minitest/autorun'
2
-
3
- require_relative '../lib/month'
4
-
5
- describe 'Month' do
6
- describe 'constructor' do
7
- it 'raises an exception when initialized with an invalid number' do
8
- proc { Month.new(2014, 0) }.must_raise(ArgumentError)
9
- proc { Month.new(2014, 100) }.must_raise(ArgumentError)
10
- end
11
-
12
- it 'returns frozen instances' do
13
- month = Month.new(2017, 1)
14
- month.frozen?.must_equal(true)
15
- end
16
- end
17
-
18
- describe 'year method' do
19
- it 'returns the integer year of the month' do
20
- Month.new(2014, 1).year.must_equal(2014)
21
- end
22
- end
23
-
24
- describe 'number method' do
25
- it 'returns the integer number of the month' do
26
- Month.new(2014, 1).number.must_equal(1)
27
- end
28
- end
29
-
30
- describe 'to_s method' do
31
- it 'returns a string containing the year and zero padded number of the month' do
32
- Month.new(2014, 1).to_s.must_equal('2014-01')
33
- end
34
- end
35
-
36
- describe 'name method' do
37
- it 'returns the name of the month' do
38
- Month.new(2014, 1).name.must_equal(:January)
39
- end
40
- end
41
-
42
- describe 'january predicate method' do
43
- it 'returns true if the month is january' do
44
- Month.new(2014, 1).january?.must_equal(true)
45
- end
46
-
47
- it 'returns false otherwise' do
48
- Month.new(2014, 2).january?.must_equal(false)
49
- end
50
- end
51
-
52
- describe 'february predicate method' do
53
- it 'returns true if the month is february' do
54
- Month.new(2014, 2).february?.must_equal(true)
55
- end
56
-
57
- it 'returns false otherwise' do
58
- Month.new(2014, 1).february?.must_equal(false)
59
- end
60
- end
61
-
62
- it 'supports being used as a hash key' do
63
- hash, n = Hash.new(0), 10
64
-
65
- n.times { hash[Month.new(2014, 1)] += 1 }
66
-
67
- hash.count.must_equal(1)
68
- hash[Month.new(2014, 1)].must_equal(n)
69
- end
70
-
71
- it 'supports comparison between month objects' do
72
- Month.new(2014, 1).must_be_kind_of(Comparable)
73
-
74
- (Month.new(2014, 1) == Month.new(2014, 1)).must_equal(true)
75
- (Month.new(2014, 1) == Month.new(2014, 2)).must_equal(false)
76
-
77
- (Month.new(2014, 1) < Month.new(2014, 2)).must_equal(true)
78
- (Month.new(2014, 2) > Month.new(2014, 1)).must_equal(true)
79
- end
80
-
81
- it 'supports comparison with nil' do
82
- (Month.new(2014, 1) == nil).must_equal(false)
83
- end
84
-
85
- it 'supports being used in a range' do
86
- range = Month.new(2014, 1) .. Month.new(2014, 4)
87
-
88
- range.map(&:number).must_equal([1, 2, 3, 4])
89
- end
90
-
91
- describe 'next method' do
92
- it 'returns a month object denoting the next month' do
93
- Month.new(2014, 1).next.must_equal(Month.new(2014, 2))
94
- Month.new(2014, 12).next.must_equal(Month.new(2015, 1))
95
- end
96
- end
97
-
98
- describe 'succ method' do
99
- it 'returns a month object denoting the next month' do
100
- Month.new(2014, 1).succ.must_equal(Month.new(2014, 2))
101
- Month.new(2014, 12).succ.must_equal(Month.new(2015, 1))
102
- end
103
- end
104
-
105
- describe '>> method' do
106
- it 'returns a month object denoting n months after' do
107
- (Month.new(2014, 1) >> 5).must_equal(Month.new(2014, 6))
108
- (Month.new(2014, 12) >> 5).must_equal(Month.new(2015, 5))
109
- (Month.new(2014, 12) >> -5).must_equal(Month.new(2014, 7))
110
- end
111
- end
112
-
113
- describe '<< method' do
114
- it 'returns a month object denoting n months before' do
115
- (Month.new(2014, 1) << 5).must_equal(Month.new(2013, 8))
116
- (Month.new(2014, 12) << 5).must_equal(Month.new(2014, 7))
117
- (Month.new(2014, 12) << -5).must_equal(Month.new(2015, 5))
118
- end
119
- end
120
-
121
- describe 'step method' do
122
- it 'calls the block for every month until the given limit' do
123
- months = []
124
-
125
- Month.new(2014, 1).step(Month.new(2014, 3)) { |month| months << month }
126
-
127
- months.must_equal([Month.new(2014, 1), Month.new(2014, 2), Month.new(2014, 3)])
128
- end
129
-
130
- it 'returns an enumerator if no block was given' do
131
- months = Month.new(2014, 1).step(Month.new(2014, 3))
132
-
133
- months.must_be_instance_of(Enumerator)
134
-
135
- months.next.must_equal(Month.new(2014, 1))
136
- months.next.must_equal(Month.new(2014, 2))
137
- months.next.must_equal(Month.new(2014, 3))
138
- end
139
-
140
- it 'raises an exception when the given step argument is zero' do
141
- proc { Month.new(2014, 1).step(Month.new(2014, 3), 0) }.must_raise(ArgumentError)
142
- end
143
-
144
- it 'increases by the given number of months if the step argument is positive' do
145
- months = []
146
-
147
- Month.new(2014, 1).step(Month.new(2014, 3), 2) { |month| months << month }
148
-
149
- months.must_equal([Month.new(2014, 1), Month.new(2014, 3)])
150
- end
151
-
152
- it 'decreases by the given number of months if the step argument is negative' do
153
- months = []
154
-
155
- Month.new(2014, 3).step(Month.new(2014, 1), -1) { |month| months << month }
156
-
157
- months.must_equal([Month.new(2014, 3), Month.new(2014, 2), Month.new(2014, 1)])
158
- end
159
- end
160
-
161
- describe 'upto method' do
162
- it 'calls the block for every month until the given limit' do
163
- months = []
164
-
165
- Month.new(2014, 1).upto(Month.new(2014, 3)) { |month| months << month }
166
-
167
- months.must_equal([Month.new(2014, 1), Month.new(2014, 2), Month.new(2014, 3)])
168
- end
169
-
170
- it 'returns an enumerator if no block was given' do
171
- months = Month.new(2014, 1).upto(Month.new(2014, 3))
172
-
173
- months.must_be_instance_of(Enumerator)
174
-
175
- months.next.must_equal(Month.new(2014, 1))
176
- months.next.must_equal(Month.new(2014, 2))
177
- months.next.must_equal(Month.new(2014, 3))
178
- end
179
- end
180
-
181
- describe 'downto method' do
182
- it 'calls the block for every month until the given limit' do
183
- months = []
184
-
185
- Month.new(2014, 3).downto(Month.new(2014, 1)) { |month| months << month }
186
-
187
- months.must_equal([Month.new(2014, 3), Month.new(2014, 2), Month.new(2014, 1)])
188
- end
189
-
190
- it 'returns an enumerator if no block was given' do
191
- months = Month.new(2014, 3).downto(Month.new(2014, 1))
192
-
193
- months.must_be_instance_of(Enumerator)
194
-
195
- months.next.must_equal(Month.new(2014, 3))
196
- months.next.must_equal(Month.new(2014, 2))
197
- months.next.must_equal(Month.new(2014, 1))
198
- end
199
- end
200
-
201
- describe 'addition' do
202
- it 'returns a month object denoting the given number of months after self' do
203
- (Month.new(2014, 1) + 1).must_equal(Month.new(2014, 2))
204
- (Month.new(2014, 1) + 12).must_equal(Month.new(2015, 1))
205
- (Month.new(2014, 1) + 18).must_equal(Month.new(2015, 7))
206
- (Month.new(2013, 11) + 1).must_equal(Month.new(2013, 12))
207
- (Month.new(2013, 11) + 2).must_equal(Month.new(2014, 1))
208
- end
209
- end
210
-
211
- describe 'subtraction' do
212
- it 'returns a month object denoting the given number of months before self' do
213
- (Month.new(2014, 2) - 1).must_equal(Month.new(2014, 1))
214
- (Month.new(2014, 1) - 1).must_equal(Month.new(2013, 12))
215
- (Month.new(2014, 1) - 12).must_equal(Month.new(2013, 1))
216
- (Month.new(2014, 1) - 18).must_equal(Month.new(2012, 7))
217
- (Month.new(2013, 12) - 1).must_equal(Month.new(2013, 11))
218
- (Month.new(2014, 1) - 2).must_equal(Month.new(2013, 11))
219
- end
220
-
221
- it 'returns the number of months between the given month and self' do
222
- (Month.new(2014, 3) - Month.new(2014, 1)).must_equal(2)
223
- (Month.new(2015, 1) - Month.new(2014, 1)).must_equal(12)
224
- (Month.new(2077, 4) - Month.new(2070, 4)).must_equal(84)
225
- end
226
- end
227
-
228
- describe 'include predicate method' do
229
- it 'returns true if the month includes the given date' do
230
- Month.new(2014, 1).include?(Date.new(2014, 1, 1)).must_equal(true)
231
- end
232
-
233
- it 'returns false otherwise' do
234
- Month.new(2014, 1).include?(Date.new(2014, 2, 1)).must_equal(false)
235
- end
236
- end
237
-
238
- describe 'case equals method' do
239
- it 'returns true if the month includes the given date' do
240
- (Month.new(2014, 1) === Date.new(2014, 1, 1)).must_equal(true)
241
- end
242
-
243
- it 'returns false otherwise' do
244
- (Month.new(2014, 1) === Date.new(2014, 2, 1)).must_equal(false)
245
- end
246
- end
247
-
248
- describe 'start_date method' do
249
- it 'returns a date object denoting the first day of the month' do
250
- Month.new(2014, 1).start_date.must_equal(Date.new(2014, 1, 1))
251
- end
252
- end
253
-
254
- describe 'end_date method' do
255
- it 'returns a date object denoting the last day of the month' do
256
- Month.new(2014, 1).end_date.must_equal(Date.new(2014, 1, 31))
257
- end
258
- end
259
-
260
- describe 'dates method' do
261
- it 'returns the range of dates in the month' do
262
- dates = Month.new(2014, 1).dates
263
- dates.must_be_instance_of(Range)
264
- dates.count.must_equal(31)
265
- dates.all? { |date| Date === date }.must_equal(true)
266
- dates.first.must_equal(Date.new(2014, 1, 1))
267
- dates.last.must_equal(Date.new(2014, 1, 31))
268
- end
269
- end
270
-
271
- describe 'length method' do
272
- it 'returns the integer number of days in the month' do
273
- Month.new(2014, 1).length.must_equal(31)
274
- Month.new(2014, 2).length.must_equal(28)
275
- end
276
- end
277
- end
278
-
279
- describe 'Month parse method' do
280
- it 'returns the month corresponding to the given string representation' do
281
- Month.parse('2014-01').must_equal(Month.new(2014, 1))
282
- end
283
-
284
- it 'raises an exception if the format of the string is not as expected' do
285
- proc { Month.parse('January 2014') }.must_raise(ArgumentError)
286
- end
287
- end
288
-
289
- describe 'Month method' do
290
- it 'returns the month of the given date object' do
291
- Month(Date.new(2014, 1, 1)).must_equal(Month.new(2014, 1))
292
- end
293
-
294
- it 'returns the month of the given time object' do
295
- Month(Time.at(1234567890)).must_equal(Month.new(2009, 2))
296
- end
297
-
298
- it 'returns the month of the given datetime object' do
299
- Month(DateTime.parse('2001-02-03T04:05:06+07:00')).must_equal(Month.new(2001, 2))
300
- end
301
-
302
- it 'returns the month of the given integer unix timestamp' do
303
- Month(1234567890).must_equal(Month.new(2009, 2))
304
- end
305
-
306
- it 'idempotently returns the given month' do
307
- month = Month.new(2014, 1)
308
-
309
- Month(month).object_id.must_equal(month.object_id)
310
- end
311
- end
312
-
313
- describe 'Month today method' do
314
- let(:current_date) { Date.today }
315
- let(:current_month) { Month.new(current_date.year, current_date.month) }
316
-
317
- it 'returns the current month' do
318
- Month.today.must_equal(current_month)
319
- end
320
- end
321
-
322
- describe 'Month now method' do
323
- let(:current_time) { Time.now }
324
- let(:current_month) { Month.new(current_time.year, current_time.month) }
325
-
326
- it 'returns the current month' do
327
- Month.now.must_equal(current_month)
328
- end
329
- end
330
-
331
- describe 'A method defined in Month::Methods' do
332
- include Month::Methods
333
-
334
- it 'returns a month object denoting that month in the given year' do
335
- month = January 2014
336
- month.must_equal(Month.new(2014, 1))
337
-
338
- month = February 2014
339
- month.must_equal(Month.new(2014, 2))
340
- end
341
-
342
- it 'returns a date object when given two arguments' do
343
- date = January 31, 2014
344
- date.must_equal(Date.new(2014, 1, 31))
345
-
346
- date = February 28, 2014
347
- date.must_equal(Date.new(2014, 2, 28))
348
- end
349
-
350
- it 'raises an exception if given too many arguments' do
351
- proc { January 1, 2, 3 }.must_raise(ArgumentError)
352
- end
353
- end