month 1.7.1 → 2.0.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: c6f2cb49e56df71efa50a5d0b1d0defa911997bb7b1f064ce4820cbb171d64b7
4
- data.tar.gz: 3d16daecccc4d6b4a8287e870f6114d51e148478aa7f26bf295a805020f9b670
3
+ metadata.gz: 4eae90e4553fd130639c8f35f5feda52af6a7a4d56ec8631981fd0cadaa1895a
4
+ data.tar.gz: 76fb1049ecc66fdd30f145f7623ce978ea8606cd415dca8c20b63978af991b42
5
5
  SHA512:
6
- metadata.gz: 9dcaed88e8f32858f302b14369a7f095bbe5e237d89599ed74bd430956946e3297c52eba4f639b94b17b7f8b9060e7b208d4360d3f8812f2ab2fc41a7970dc62
7
- data.tar.gz: 6d0627f52ef61f665be335c66734cf9e0fcce5d0751bf9bf08c07aaf195b6209fb970cf0696625d3667dce68350fcc7c55e34fbb7b2c7ba45bdf13acc14a5de0
6
+ metadata.gz: 6d6ee334ce0de8c6162fb51ea14950e1d18fe085ce3818f290ab2a578a383853193c2f1606c16886dd978ee1bed750308d90a7eced6a24d7b62c3a1ed69cc71d
7
+ data.tar.gz: 15a1e39f3722c920152f3ae36301a149ddf520f7dce91b6591ed6b4c25cdcf5a2f46f6e2221651d8ff82007d93d4f1b46036d4d5fbb527006d646250e9324a47
data/CHANGES.md CHANGED
@@ -1,3 +1,15 @@
1
+ # 2.0.0
2
+
3
+ * Changed required_ruby_version to >= 2.6.0
4
+
5
+ * Fixed Month#next_month and Month#prev_month methods
6
+
7
+ * Added functionality for parsing strings like '2014 JAN'
8
+
9
+ * Added functionality for parsing strings like 'January 2014'
10
+
11
+ * Removed Month.today method in favour of Month.now method
12
+
1
13
  # 1.7.1
2
14
 
3
15
  * Added CHANGES.md to gem files
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014-2020 TIMCRAFT
1
+ Copyright (c) 2014-2022 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,7 +1,7 @@
1
1
  # month
2
2
 
3
3
  ![Gem Version](https://badge.fury.io/rb/month.svg)
4
- ![Build Status](https://github.com/readysteady/month/workflows/Test/badge.svg)
4
+ ![Test Status](https://github.com/readysteady/month/actions/workflows/test.yml/badge.svg)
5
5
 
6
6
 
7
7
  Ruby gem for working with months.
data/lib/month.rb CHANGED
@@ -32,7 +32,7 @@ class Month
32
32
  alias_method :month, :number
33
33
 
34
34
  def to_s
35
- "#@year-#{@number.to_s.rjust(2, '0')}"
35
+ "#{@year}-#{@number.to_s.rjust(2, '0')}"
36
36
  end
37
37
 
38
38
  alias_method :iso8601, :to_s
@@ -77,18 +77,20 @@ class Month
77
77
 
78
78
  alias_method :succ, :next
79
79
 
80
+ alias_method :next_month, :next
81
+
82
+ def prev_month
83
+ self - 1
84
+ end
85
+
80
86
  def >>(n)
81
87
  self + n
82
88
  end
83
89
 
84
- alias_method :next_month, :>>
85
-
86
90
  def <<(n)
87
91
  self - n
88
92
  end
89
93
 
90
- alias_method :prev_month, :<<
91
-
92
94
  def step(limit, step = 1)
93
95
  raise ArgumentError if step.zero?
94
96
 
@@ -135,8 +137,8 @@ class Month
135
137
  end
136
138
  end
137
139
 
138
- def include?(date)
139
- @year == date.year && @number == date.month
140
+ def include?(time)
141
+ @year == time.year && @number == time.month
140
142
  end
141
143
 
142
144
  alias_method :===, :include?
@@ -159,13 +161,38 @@ class Month
159
161
  end
160
162
 
161
163
  class Month
162
- REGEXP = /\A(\d{4})-(\d{2})\z/
164
+ ABBREVIATIONS = {
165
+ 'JAN' => 1,
166
+ 'FEB' => 2,
167
+ 'MAR' => 3,
168
+ 'APR' => 4,
169
+ 'MAY' => 5,
170
+ 'JUN' => 6,
171
+ 'JUL' => 7,
172
+ 'AUG' => 8,
173
+ 'SEP' => 9,
174
+ 'OCT' => 10,
175
+ 'NOV' => 11,
176
+ 'DEC' => 12,
177
+ }
178
+
179
+ REGEXP1 = /\A(\d{4})-(\d{2})\z/
180
+ REGEXP2 = /\A(\d{4}) (#{ABBREVIATIONS.keys.join('|')})\z/
181
+ REGEXP3 = /\A(#{Date::MONTHNAMES.compact.join('|')}) (\d{4})\z/
163
182
 
164
- private_constant :REGEXP
183
+ private_constant :ABBREVIATIONS
184
+ private_constant :REGEXP1
185
+ private_constant :REGEXP2
186
+ private_constant :REGEXP3
165
187
 
166
188
  def self.parse(string)
167
- if string =~ REGEXP
189
+ case string
190
+ when REGEXP1
168
191
  Month.new($1.to_i, $2.to_i)
192
+ when REGEXP2
193
+ Month.new($1.to_i, ABBREVIATIONS.fetch($2))
194
+ when REGEXP3
195
+ Month.new($2.to_i, Date::MONTHNAMES.index($1))
169
196
  else
170
197
  raise ArgumentError, 'invalid month'
171
198
  end
@@ -183,10 +210,6 @@ def Month(object)
183
210
  end
184
211
  end
185
212
 
186
- def Month.today
187
- Month(Date.today)
188
- end
189
-
190
213
  def Month.now
191
214
  Month(Time.now)
192
215
  end
data/month.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'month'
3
- s.version = '1.7.1'
3
+ s.version = '2.0.0'
4
4
  s.license = 'MIT'
5
5
  s.platform = Gem::Platform::RUBY
6
6
  s.authors = ['Tim Craft']
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
9
9
  s.description = 'Ruby gem for working with months'
10
10
  s.summary = 'See description'
11
11
  s.files = Dir.glob('lib/**/*.rb') + %w[CHANGES.md LICENSE.txt README.md month.gemspec]
12
- s.required_ruby_version = '>= 1.9.3'
12
+ s.required_ruby_version = '>= 2.6.0'
13
13
  s.require_path = 'lib'
14
14
  s.metadata = {
15
15
  'homepage' => 'https://github.com/readysteady/month',
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.7.1
4
+ version: 2.0.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: 2020-11-03 00:00:00.000000000 Z
11
+ date: 2022-01-24 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Ruby gem for working with months
14
14
  email:
@@ -39,14 +39,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
39
39
  requirements:
40
40
  - - ">="
41
41
  - !ruby/object:Gem::Version
42
- version: 1.9.3
42
+ version: 2.6.0
43
43
  required_rubygems_version: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  requirements: []
49
- rubygems_version: 3.1.4
49
+ rubygems_version: 3.2.32
50
50
  signing_key:
51
51
  specification_version: 4
52
52
  summary: See description