month 1.4.0 → 1.5.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: 5b3bdca8b5d09040c1b4ac4acae05c8e03547c5e6ff020e59535cc5755df14b2
4
- data.tar.gz: 916f1bc25bdc43daac8a90681c9c0d02add86c46cce4096aaaae84ef5be7d3e9
3
+ metadata.gz: 4009cafb1322ac57f543f1890b413d8082e504720535272ea0de0fb73d82c184
4
+ data.tar.gz: fdc90cf876afdc7113d69c80fa1dad52a8d54a97d391ce75b3a500fc82e185a7
5
5
  SHA512:
6
- metadata.gz: 7a8be4984db7ecd605a9384ae9fb337af3227d7bf35683fa436a090ef232b4aa5efcd3d49c42858c4ace3a94691419868e166382417d1070bdc3959bdbdf487e
7
- data.tar.gz: 84acf9a45e4641ccf2ebf1adb697e1c98b13d55679c65ef04d5b02176f8e9de08b8450e883360edc8bcd7c523497442df973e13039b3111639b9c267ad58acb5
6
+ metadata.gz: 2c1b9f286ac469bfe6b2d1281a07085ca79e5305ed3ca22c39f7545c10ca0caae84b888a31be84dc75e9e823290ef847635d1c0ef1ef2b5c28055b8b68a4206e
7
+ data.tar.gz: b90587bf792e723dc9b59ef8814ffc6165e251c2da8afe596075f0667208781042c140f230707470df6fbdc2cdb3938ae7e426e7a869d206fcb43cd0f846bd1a
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014-2018 TIMCRAFT
1
+ Copyright (c) 2014-2019 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
@@ -72,6 +72,18 @@ class Month
72
72
 
73
73
  alias_method :succ, :next
74
74
 
75
+ def >>(n)
76
+ self + n
77
+ end
78
+
79
+ alias_method :next_month, :>>
80
+
81
+ def <<(n)
82
+ self - n
83
+ end
84
+
85
+ alias_method :prev_month, :<<
86
+
75
87
  def step(limit, step = 1)
76
88
  raise ArgumentError if step.zero?
77
89
 
@@ -114,7 +126,7 @@ class Month
114
126
  if object.is_a?(Integer)
115
127
  self + (-object)
116
128
  else
117
- (year * 12 + @number) - (object.year * 12 + object.number)
129
+ 12 * (year - object.year) + (@number - object.number)
118
130
  end
119
131
  end
120
132
 
@@ -160,6 +172,14 @@ def Month(object)
160
172
  end
161
173
  end
162
174
 
175
+ def Month.today
176
+ Month(Date.today)
177
+ end
178
+
179
+ def Month.now
180
+ Month(Time.now)
181
+ end
182
+
163
183
  class Month
164
184
  module Methods
165
185
  NAMES.each do |number, name|
@@ -1,16 +1,16 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'month'
3
- s.version = '1.4.0'
3
+ s.version = '1.5.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 = 'http://github.com/timcraft/month'
8
+ s.homepage = 'https://github.com/timcraft/month'
9
9
  s.description = 'A little Ruby library for working with months'
10
10
  s.summary = 'See description'
11
11
  s.files = Dir.glob('{lib,spec}/**/*') + %w(LICENSE.txt README.md month.gemspec)
12
12
  s.required_ruby_version = '>= 1.9.3'
13
- s.add_development_dependency('rake', '>= 12')
13
+ s.add_development_dependency('rake', '~> 12')
14
14
  s.add_development_dependency('minitest', '~> 5')
15
15
  s.require_path = 'lib'
16
16
  end
@@ -102,6 +102,22 @@ describe 'Month' do
102
102
  end
103
103
  end
104
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
+
105
121
  describe 'step method' do
106
122
  it 'calls the block for every month until the given limit' do
107
123
  months = []
@@ -294,6 +310,24 @@ describe 'Month method' do
294
310
  end
295
311
  end
296
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
+
297
331
  describe 'A method defined in Month::Methods' do
298
332
  include Month::Methods
299
333
 
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: month
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.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: 2018-10-08 00:00:00.000000000 Z
11
+ date: 2019-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '12'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '12'
27
27
  - !ruby/object:Gem::Dependency
@@ -50,7 +50,7 @@ files:
50
50
  - lib/month.rb
51
51
  - month.gemspec
52
52
  - spec/month_spec.rb
53
- homepage: http://github.com/timcraft/month
53
+ homepage: https://github.com/timcraft/month
54
54
  licenses:
55
55
  - MIT
56
56
  metadata: {}
@@ -69,8 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
69
  - !ruby/object:Gem::Version
70
70
  version: '0'
71
71
  requirements: []
72
- rubyforge_project:
73
- rubygems_version: 2.7.6
72
+ rubygems_version: 3.0.1
74
73
  signing_key:
75
74
  specification_version: 4
76
75
  summary: See description