month 2.0.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 +19 -1
  3. data/LICENSE.txt +1 -1
  4. data/README.md +28 -9
  5. data/lib/month.rb +41 -25
  6. data/month.gemspec +5 -5
  7. metadata +7 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4eae90e4553fd130639c8f35f5feda52af6a7a4d56ec8631981fd0cadaa1895a
4
- data.tar.gz: 76fb1049ecc66fdd30f145f7623ce978ea8606cd415dca8c20b63978af991b42
3
+ metadata.gz: df66639ee93dc9ca600737c9077b39990678aef7393d7830078ad21d86eb66cc
4
+ data.tar.gz: '060587dbe7b2d52ed383f6dcc0d81b631b399da160d0f1b3af373e131a174529'
5
5
  SHA512:
6
- metadata.gz: 6d6ee334ce0de8c6162fb51ea14950e1d18fe085ce3818f290ab2a578a383853193c2f1606c16886dd978ee1bed750308d90a7eced6a24d7b62c3a1ed69cc71d
7
- data.tar.gz: 15a1e39f3722c920152f3ae36301a149ddf520f7dce91b6591ed6b4c25cdcf5a2f46f6e2221651d8ff82007d93d4f1b46036d4d5fbb527006d646250e9324a47
6
+ metadata.gz: f9c7f9038cd81871fc28d3a9b3ac72e4df36368373dfb2bc31d31424c1b50b06ac1bd323fe4e2aa2768bcd22b6a766c0c0747862daa03e96c2c71abdbedc4732
7
+ data.tar.gz: dc1b91253191a21b1da51c563ac877083f84c7ab723cb3d69e2ca0ae4f81c007165589ae78b4bf9e0fd1ec345454f24a57a451d972f5e5056347d193b274ee63
data/CHANGES.md CHANGED
@@ -1,6 +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
+
15
+ # 2.1.0
16
+
17
+ * Added Month#inspect method
18
+
1
19
  # 2.0.0
2
20
 
3
- * Changed required_ruby_version to >= 2.6.0
21
+ * **Changed required_ruby_version to >= 2.6.0**
4
22
 
5
23
  * Fixed Month#next_month and Month#prev_month methods
6
24
 
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014-2022 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
 
@@ -37,22 +26,37 @@ class Month
37
26
 
38
27
  alias_method :iso8601, :to_s
39
28
 
40
- def name
41
- NAMES.fetch(@number)
29
+ def inspect
30
+ "<Month: #{to_s}>"
42
31
  end
43
32
 
44
- NAMES.each do |number, name|
45
- define_method(:"#{name.downcase}?") do
46
- @number == number
47
- end
48
- end
33
+ def name
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
49
49
 
50
50
  def hash
51
51
  [@year, @number].hash
52
52
  end
53
53
 
54
54
  def eql?(object)
55
- 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}
56
60
  end
57
61
 
58
62
  def <=>(month)
@@ -143,6 +147,14 @@ class Month
143
147
 
144
148
  alias_method :===, :include?
145
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
+
146
158
  def start_date
147
159
  Date.new(@year, @number, 1)
148
160
  end
@@ -155,6 +167,8 @@ class Month
155
167
  start_date .. end_date
156
168
  end
157
169
 
170
+ alias_method :date_range, :dates
171
+
158
172
  def length
159
173
  end_date.mday
160
174
  end
@@ -216,7 +230,9 @@ end
216
230
 
217
231
  class Month
218
232
  module Methods
219
- NAMES.each do |number, name|
233
+ Date::MONTHNAMES.each_with_index do |name, number|
234
+ next if name.nil?
235
+
220
236
  define_method(name) do |*args|
221
237
  case args.length
222
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.0.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
- s.email = ['mail@timcraft.com']
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,18 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: month
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Craft
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2022-01-24 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies: []
13
- description: Ruby gem for working with months
12
+ description: Ruby gem for working with calendar months
14
13
  email:
15
- - mail@timcraft.com
14
+ - email@timcraft.com
16
15
  executables: []
17
16
  extensions: []
18
17
  extra_rdoc_files: []
@@ -31,7 +30,6 @@ metadata:
31
30
  source_code_uri: https://github.com/readysteady/month
32
31
  bug_tracker_uri: https://github.com/readysteady/month/issues
33
32
  changelog_uri: https://github.com/readysteady/month/blob/main/CHANGES.md
34
- post_install_message:
35
33
  rdoc_options: []
36
34
  require_paths:
37
35
  - lib
@@ -39,15 +37,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
39
37
  requirements:
40
38
  - - ">="
41
39
  - !ruby/object:Gem::Version
42
- version: 2.6.0
40
+ version: 3.0.0
43
41
  required_rubygems_version: !ruby/object:Gem::Requirement
44
42
  requirements:
45
43
  - - ">="
46
44
  - !ruby/object:Gem::Version
47
45
  version: '0'
48
46
  requirements: []
49
- rubygems_version: 3.2.32
50
- signing_key:
47
+ rubygems_version: 4.0.10
51
48
  specification_version: 4
52
- summary: See description
49
+ summary: Ruby gem for working with calendar months
53
50
  test_files: []