month 2.1.0 → 3.0.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.
Files changed (7) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +15 -1
  3. data/LICENSE.txt +1 -1
  4. data/README.md +28 -9
  5. data/lib/month.rb +38 -26
  6. data/month.gemspec +4 -4
  7. metadata +6 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1e3aca66897fb2dc1cb5c5c6f2b34d7f5611f0727bed247a0676aeb9cd09dba8
4
- data.tar.gz: ae9b57770644dd9f62945db5712372743d198e034f8c6dae3b447c0cf78d8eda
3
+ metadata.gz: df66639ee93dc9ca600737c9077b39990678aef7393d7830078ad21d86eb66cc
4
+ data.tar.gz: '060587dbe7b2d52ed383f6dcc0d81b631b399da160d0f1b3af373e131a174529'
5
5
  SHA512:
6
- metadata.gz: b17a3f52d33950f8dc85449dc934b43470aa6be0c55d33a919b3247a56d1645fe9da491447ce133840ee1859e453255d8ba9bc3da664b2a389cbc52b7486ed7a
7
- data.tar.gz: 389db54dbe6083a165d169ed4272943fef8ee3d77a6f74f8b8ba575bf152dff3fc91566d7c1cf9666e9a75ef285bdf6509bdbb0e8914ec6362f65e7a0ab94b8d
6
+ metadata.gz: f9c7f9038cd81871fc28d3a9b3ac72e4df36368373dfb2bc31d31424c1b50b06ac1bd323fe4e2aa2768bcd22b6a766c0c0747862daa03e96c2c71abdbedc4732
7
+ data.tar.gz: dc1b91253191a21b1da51c563ac877083f84c7ab723cb3d69e2ca0ae4f81c007165589ae78b4bf9e0fd1ec345454f24a57a451d972f5e5056347d193b274ee63
data/CHANGES.md CHANGED
@@ -1,10 +1,24 @@
1
+ # 3.0.0
2
+
3
+ * **Changed required_ruby_version to >= 3.0.0**
4
+
5
+ * Added Month#deconstruct_keys method
6
+
7
+ * Added Month#date_range alias for Month#dates
8
+
9
+ * Added Month#start_time method and Month#end_time methods
10
+
11
+ * Changed Month#name to return strings instead of symbols
12
+
13
+ * Removed Month::NAMES constant
14
+
1
15
  # 2.1.0
2
16
 
3
17
  * Added Month#inspect method
4
18
 
5
19
  # 2.0.0
6
20
 
7
- * Changed required_ruby_version to >= 2.6.0
21
+ * **Changed required_ruby_version to >= 2.6.0**
8
22
 
9
23
  * Fixed Month#next_month and Month#prev_month methods
10
24
 
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014-2025 TIMCRAFT
1
+ Copyright (c) 2014-2026 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,10 +1,6 @@
1
1
  # month
2
2
 
3
- ![Gem Version](https://badge.fury.io/rb/month.svg)
4
- ![Test Status](https://github.com/readysteady/month/actions/workflows/test.yml/badge.svg)
5
-
6
-
7
- Ruby gem for working with months.
3
+ Ruby gem for working with calendar months.
8
4
 
9
5
 
10
6
  ## Install
@@ -114,13 +110,36 @@ The #length method returns the number of days in the month:
114
110
  Month.new(2014, 1).length # 31
115
111
  ```
116
112
 
117
- Month objects can be used in case expressions.
113
+ Month objects can be used in case expressions to match date/time objects:
114
+
115
+ ```ruby
116
+ case datetime
117
+ when month
118
+ puts "Date/time is in #{month}"
119
+ end
120
+ ```
121
+
122
+ Month objects can be used as hash keys for counting, grouping etc:
123
+
124
+ ```ruby
125
+ totals = {
126
+ Month.new(2014, 1) => 0
127
+ }
128
+ ```
129
+
130
+ Month objects can be used in ranges:
131
+
132
+ ```ruby
133
+ months = Month.new(2014, 1) .. Month.new(2014, 12)
134
+ ```
118
135
 
119
- Month objects can be used as hash keys.
136
+ Month objects are comparable:
120
137
 
121
- Month objects can be used in ranges.
138
+ ```ruby
139
+ Month.new(2014, 1) < Month.new(2014, 2) # true
140
+ ```
122
141
 
123
- Month objects are comparable.
142
+ Month objects are ractor-safe.
124
143
 
125
144
 
126
145
  ## Bonus extras
data/lib/month.rb CHANGED
@@ -2,23 +2,12 @@
2
2
  require 'date'
3
3
 
4
4
  class Month
5
- NAMES = {
6
- 1 => :January,
7
- 2 => :February,
8
- 3 => :March,
9
- 4 => :April,
10
- 5 => :May,
11
- 6 => :June,
12
- 7 => :July,
13
- 8 => :August,
14
- 9 => :September,
15
- 10 => :October,
16
- 11 => :November,
17
- 12 => :December
18
- }
19
-
20
5
  def initialize(year, number)
21
- unless NAMES.key?(number)
6
+ unless year.is_a?(Integer)
7
+ raise ArgumentError, 'invalid year'
8
+ end
9
+
10
+ unless number.is_a?(Integer) && number.between?(1, 12)
22
11
  raise ArgumentError, 'invalid month number'
23
12
  end
24
13
 
@@ -42,21 +31,32 @@ class Month
42
31
  end
43
32
 
44
33
  def name
45
- NAMES.fetch(@number)
46
- end
47
-
48
- NAMES.each do |number, name|
49
- define_method(:"#{name.downcase}?") do
50
- @number == number
51
- end
52
- end
34
+ Date::MONTHNAMES[@number]
35
+ end
36
+
37
+ def january?; @number == 1; end
38
+ def february?; @number == 2; end
39
+ def march?; @number == 3; end
40
+ def april?; @number == 4; end
41
+ def may?; @number == 5; end
42
+ def june?; @number == 6; end
43
+ def july?; @number == 7; end
44
+ def august?; @number == 8; end
45
+ def september?; @number == 9; end
46
+ def october?; @number == 10; end
47
+ def november?; @number == 11; end
48
+ def december?; @number == 12; end
53
49
 
54
50
  def hash
55
51
  [@year, @number].hash
56
52
  end
57
53
 
58
54
  def eql?(object)
59
- object.class == self.class && object.hash == self.hash
55
+ object.class == self.class && object.year == @year && object.number == @number
56
+ end
57
+
58
+ def deconstruct_keys(keys)
59
+ {year: @year, number: @number}
60
60
  end
61
61
 
62
62
  def <=>(month)
@@ -147,6 +147,14 @@ class Month
147
147
 
148
148
  alias_method :===, :include?
149
149
 
150
+ def start_time
151
+ Time.new(@year, @number, 1, 0, 0, 0)
152
+ end
153
+
154
+ def end_time
155
+ Time.new(@year, @number, end_date.day, 23, 59, 59)
156
+ end
157
+
150
158
  def start_date
151
159
  Date.new(@year, @number, 1)
152
160
  end
@@ -159,6 +167,8 @@ class Month
159
167
  start_date .. end_date
160
168
  end
161
169
 
170
+ alias_method :date_range, :dates
171
+
162
172
  def length
163
173
  end_date.mday
164
174
  end
@@ -220,7 +230,9 @@ end
220
230
 
221
231
  class Month
222
232
  module Methods
223
- NAMES.each do |number, name|
233
+ Date::MONTHNAMES.each_with_index do |name, number|
234
+ next if name.nil?
235
+
224
236
  define_method(name) do |*args|
225
237
  case args.length
226
238
  when 1
data/month.gemspec CHANGED
@@ -1,15 +1,15 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'month'
3
- s.version = '2.1.0'
3
+ s.version = '3.0.0'
4
4
  s.license = 'MIT'
5
5
  s.platform = Gem::Platform::RUBY
6
6
  s.authors = ['Tim Craft']
7
7
  s.email = ['email@timcraft.com']
8
8
  s.homepage = 'https://github.com/readysteady/month'
9
- s.description = 'Ruby gem for working with months'
10
- s.summary = 'See description'
9
+ s.description = 'Ruby gem for working with calendar months'
10
+ s.summary = 'Ruby gem for working with calendar months'
11
11
  s.files = Dir.glob('lib/**/*.rb') + %w[CHANGES.md LICENSE.txt README.md month.gemspec]
12
- s.required_ruby_version = '>= 2.6.0'
12
+ s.required_ruby_version = '>= 3.0.0'
13
13
  s.require_path = 'lib'
14
14
  s.metadata = {
15
15
  'homepage' => 'https://github.com/readysteady/month',
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: month
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Craft
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-01-02 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies: []
12
- description: Ruby gem for working with months
12
+ description: Ruby gem for working with calendar months
13
13
  email:
14
14
  - email@timcraft.com
15
15
  executables: []
@@ -37,14 +37,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 2.6.0
40
+ version: 3.0.0
41
41
  required_rubygems_version: !ruby/object:Gem::Requirement
42
42
  requirements:
43
43
  - - ">="
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
46
  requirements: []
47
- rubygems_version: 3.6.2
47
+ rubygems_version: 4.0.10
48
48
  specification_version: 4
49
- summary: See description
49
+ summary: Ruby gem for working with calendar months
50
50
  test_files: []