month 1.0.0 → 1.1.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
  SHA1:
3
- metadata.gz: c7a5b582cedcab3ae50a07ede99a2036cdf836d6
4
- data.tar.gz: 74a2c8bfc2bf430a86cf9b1edadb26d20f047db8
3
+ metadata.gz: 3f998e2e63d6369b8d84bfbfa5702e905ea7a902
4
+ data.tar.gz: eb30605ca6b103a606a74fe833f191d24847c37d
5
5
  SHA512:
6
- metadata.gz: 2a262762f6b7699fc8031a4d4d304b85751682d7d5efa3e769961c379cf306b6ffeaeb1518067100befe4c3a7998bb1846f005a992a5b1ff22918377fdb55462
7
- data.tar.gz: d069fd96c3e81f3e4b19d9e851103db1199d42ca100733b323b0ea680cf948bf985a412356d7f03a150f8b0d3da752e24dffae611525e1dff481ff5d9a19e970
6
+ metadata.gz: 8de438f976fd1e79aa70c61bc900d99658ba70abaf59e254b37e486bfcceb7b504376bf373a2a2679315a06ef694ab15f69e5168e2aa9a16ab98417c7e8288ed
7
+ data.tar.gz: dba1269a852a8d2a1974a931fd79f03d16dcb94ac9eb3d68b2d9e7ef54b6058b6b227f27c47af7b6a7311943f06e2e6cec993929fa83377517bab63360f18aa5
data/README.md CHANGED
@@ -5,11 +5,16 @@ month
5
5
  A little library for working with months.
6
6
 
7
7
 
8
+ Installation
9
+ ------------
10
+
11
+ $ gem install month
12
+
13
+
8
14
  Feature tour
9
15
  ------------
10
16
 
11
- You can create a new Month object by passing the year and the month number
12
- as arguments to the constructor:
17
+ You can create a new Month object with a year and month number:
13
18
 
14
19
  ```ruby
15
20
  Month.new(2014, 1) # January 2014
@@ -126,5 +131,13 @@ month = January 2014
126
131
  date = January 15, 2014
127
132
  ```
128
133
 
129
- It is not included by default, you can either include it within your
130
- own modules/classes or globally within your application/script.
134
+ It is not included globally by default; you can either include it within
135
+ your own modules/classes or globally within your own application/script.
136
+
137
+
138
+ History
139
+ -------
140
+
141
+ This current implementation is an accidental rewrite of an older library/gem
142
+ with the same name/purpose ([fhwang / month](https://github.com/fhwang/month)).
143
+ Thanks to Francis for kindly allowing me to re-use the same gem name.
@@ -83,20 +83,16 @@ class Month
83
83
  end
84
84
 
85
85
  def +(number)
86
- a, b = (@number + number).divmod(12)
86
+ a, b = (@number - 1 + number).divmod(12)
87
87
 
88
- self.class.new(@year + a, b)
88
+ self.class.new(@year + a, b + 1)
89
89
  end
90
90
 
91
- def -(number)
92
- if @number > number
93
- self.class.new(@year, @number - number)
94
- elsif @number < number
95
- a, b = (@number - number).divmod(12)
96
-
97
- self.class.new(@year + a, b)
91
+ def -(object)
92
+ if object.is_a?(Integer)
93
+ self + (-object)
98
94
  else
99
- self.class.new(@year - 1, 12)
95
+ (year * 12 + @number) - (object.year * 12 + object.number)
100
96
  end
101
97
  end
102
98
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'month'
3
- s.version = '1.0.0'
3
+ s.version = '1.1.0'
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.authors = ['Tim Craft']
6
6
  s.email = ['mail@timcraft.com']
@@ -8,6 +8,7 @@ Gem::Specification.new do |s|
8
8
  s.description = 'A little library for working with months'
9
9
  s.summary = 'See description'
10
10
  s.files = Dir.glob('{lib,spec}/**/*') + %w(README.md month.gemspec)
11
+ s.required_ruby_version = '>= 1.9.3'
11
12
  s.add_development_dependency('rake', '~> 10.0')
12
13
  s.add_development_dependency('minitest', '~> 5.0')
13
14
  s.require_path = 'lib'
@@ -116,6 +116,8 @@ describe 'Month' do
116
116
  (Month.new(2014, 1) + 1).must_equal(Month.new(2014, 2))
117
117
  (Month.new(2014, 1) + 12).must_equal(Month.new(2015, 1))
118
118
  (Month.new(2014, 1) + 18).must_equal(Month.new(2015, 7))
119
+ (Month.new(2013, 11) + 1).must_equal(Month.new(2013, 12))
120
+ (Month.new(2013, 11) + 2).must_equal(Month.new(2014, 1))
119
121
  end
120
122
  end
121
123
 
@@ -125,6 +127,14 @@ describe 'Month' do
125
127
  (Month.new(2014, 1) - 1).must_equal(Month.new(2013, 12))
126
128
  (Month.new(2014, 1) - 12).must_equal(Month.new(2013, 1))
127
129
  (Month.new(2014, 1) - 18).must_equal(Month.new(2012, 7))
130
+ (Month.new(2013, 12) - 1).must_equal(Month.new(2013, 11))
131
+ (Month.new(2014, 1) - 2).must_equal(Month.new(2013, 11))
132
+ end
133
+
134
+ it 'returns the number of months between the given month and self' do
135
+ (Month.new(2014, 3) - Month.new(2014, 1)).must_equal(2)
136
+ (Month.new(2015, 1) - Month.new(2014, 1)).must_equal(12)
137
+ (Month.new(2077, 4) - Month.new(2070, 4)).must_equal(84)
128
138
  end
129
139
  end
130
140
 
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.0.0
4
+ version: 1.1.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-03-07 00:00:00.000000000 Z
11
+ date: 2014-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -60,7 +60,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
60
60
  requirements:
61
61
  - - ">="
62
62
  - !ruby/object:Gem::Version
63
- version: '0'
63
+ version: 1.9.3
64
64
  required_rubygems_version: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ">="