nth_weekday 0.1.0 ā 0.1.1
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.
- checksums.yaml +4 -4
- data/README.md +30 -3
- data/Rakefile +4 -2
- data/VERSION +1 -1
- data/examples/basic_usage.rb +2 -0
- data/examples/simple_demo.rb +3 -2
- data/lib/nth_weekday.rb +18 -16
- metadata +2 -44
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 17898431f95d95110a7939d73ecdfb186d6316cafb2e8fe193ed8d7ba4cf1f51
|
|
4
|
+
data.tar.gz: 52099f02ab6e904e90d234135f17d1782b43c5999bf86dbbf5878d7caa7951de
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 209ded1597fb87f51fc2752c1c768244ca8d5fda78ba6ecf1a52caf4583587e1d63121e953f8fe7fb38af227231934dd41c7597628930840cc1a6dae4e0000c4
|
|
7
|
+
data.tar.gz: 01260b0b375215f8dfb920f41deda20446273e9015b3542177bb79f117cbd7f38755beb813f03e19797023570a0adb5e6553048d070f3b8c56e1a80beb803672
|
data/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# nth_weekday
|
|
2
2
|
|
|
3
|
-
[](https://rubygems.org/gems/nth_weekday)
|
|
4
4
|
[](https://github.com/yusukehigasa/nth_weekday/actions)
|
|
5
5
|
|
|
6
6
|
---
|
|
@@ -30,6 +30,10 @@ gem 'nth_weekday'
|
|
|
30
30
|
gem install nth_weekday
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
+
## š» Requirements / åä½ē°å¢
|
|
34
|
+
|
|
35
|
+
- Ruby 3.3.0仄äø
|
|
36
|
+
|
|
33
37
|
## š Usage / 使ćę¹
|
|
34
38
|
|
|
35
39
|
```ruby
|
|
@@ -50,9 +54,18 @@ NthWeekday.get(year: 2025, month: 12, weekday: :fr, nth: -1)
|
|
|
50
54
|
|--------------|--------|-------------------------------------------------------|
|
|
51
55
|
| `year` | Integer| 対豔幓ļ¼ä¾: 2025ļ¼ |
|
|
52
56
|
| `month` | Integer| 対豔ęļ¼1ć12ļ¼ |
|
|
53
|
-
| `weekday` | Symbol |
|
|
57
|
+
| `weekday` | Symbol | 対豔ęę„ļ¼`:su`, `:mo`, `:tu`, `:we`, `:th`, `:fr`, `:sa`ļ¼ |
|
|
54
58
|
| `nth` | Integer| 第nāÆęę„ć1ć5ćć¾ć㯠`-1` ć§ćęå¾ć®āÆęę„ććęå® |
|
|
55
59
|
|
|
60
|
+
### ęę„ć·ć³ćć«äøč¦§
|
|
61
|
+
- `:su` - ę„ęę„ (Sunday)
|
|
62
|
+
- `:mo` - ęęę„ (Monday)
|
|
63
|
+
- `:tu` - ē«ęę„ (Tuesday)
|
|
64
|
+
- `:we` - ę°“ęę„ (Wednesday)
|
|
65
|
+
- `:th` - ęØęę„ (Thursday)
|
|
66
|
+
- `:fr` - éęę„ (Friday)
|
|
67
|
+
- `:sa` - åęę„ (Saturday)
|
|
68
|
+
|
|
56
69
|
## š§Ŗ Example: 2025幓ć®åęć®ē¬¬3ę°“ęę„ćåå¾
|
|
57
70
|
|
|
58
71
|
```ruby
|
|
@@ -68,9 +81,22 @@ end
|
|
|
68
81
|
git clone https://github.com/yusukehigasa/nth_weekday.git
|
|
69
82
|
cd nth_weekday
|
|
70
83
|
bundle install
|
|
71
|
-
rspec
|
|
84
|
+
bundle exec rspec # ćć¹ćå®č”
|
|
85
|
+
bundle exec rubocop # ć³ć¼ćć¹ćæć¤ć«ćć§ććÆ
|
|
72
86
|
```
|
|
73
87
|
|
|
88
|
+
ćć®ćććøć§ćÆćć§ćÆ [RuboCop](https://rubocop.org/) ć使ēØćć¦ć³ć¼ćć¹ćæć¤ć«ćäøč²«ćć¦ē¶ęćć¦ćć¾ććć³ć¼ćå¤ę“ę㯠`bundle exec rubocop` ć§ć¹ćæć¤ć«ćć§ććÆćå®č”ćć¦ćć ććć
|
|
89
|
+
|
|
90
|
+
## š„ Contributing / č²¢ē®
|
|
91
|
+
|
|
92
|
+
1. Fork the repository
|
|
93
|
+
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
94
|
+
3. Commit your changes (`git commit -am 'Add some amazing feature'`)
|
|
95
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
96
|
+
5. Create a new Pull Request
|
|
97
|
+
|
|
98
|
+
ćć°å ±åćę©č½č¦ęćÆ[GitHub Issues](https://github.com/yusukehigasa/nth_weekday/issues)ć«ćé”ććć¾ćć
|
|
99
|
+
|
|
74
100
|
## š License
|
|
75
101
|
|
|
76
102
|
- MIT License
|
|
@@ -83,3 +109,4 @@ rspec
|
|
|
83
109
|
|
|
84
110
|
- [RubyGems - nth_weekday](https://rubygems.org/gems/nth_weekday)
|
|
85
111
|
- [GitHub Repository](https://github.com/yusukehigasa/nth_weekday)
|
|
112
|
+
- [Changelog](https://github.com/yusukehigasa/nth_weekday/blob/main/CHANGELOG.md)
|
data/Rakefile
CHANGED
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.1.
|
|
1
|
+
0.1.1
|
data/examples/basic_usage.rb
CHANGED
data/examples/simple_demo.rb
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
2
3
|
|
|
3
4
|
require 'nth_weekday'
|
|
4
5
|
|
|
5
|
-
puts
|
|
6
|
-
puts
|
|
6
|
+
puts 'NthWeekday gem example'
|
|
7
|
+
puts '======================='
|
|
7
8
|
|
|
8
9
|
# 2025幓5ęć®ē¬¬2ęęę„ćåå¾
|
|
9
10
|
monday = NthWeekday.get(year: 2025, month: 5, weekday: :mo, nth: 2)
|
data/lib/nth_weekday.rb
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'date'
|
|
2
4
|
|
|
3
5
|
# NthWeekday module - Get specific weekdays (like 3rd Wednesday) from any year/month
|
|
4
6
|
module NthWeekday
|
|
5
7
|
# Mapping of weekday symbols to Date's wday values (0-6, Sunday is 0)
|
|
6
8
|
WEEKDAY_MAP = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
su: 0, # Sunday
|
|
10
|
+
mo: 1, # Monday
|
|
11
|
+
tu: 2, # Tuesday
|
|
12
|
+
we: 3, # Wednesday
|
|
13
|
+
th: 4, # Thursday
|
|
14
|
+
fr: 5, # Friday
|
|
15
|
+
sa: 6 # Saturday
|
|
14
16
|
}.freeze
|
|
15
17
|
|
|
16
18
|
class << self
|
|
@@ -23,26 +25,26 @@ module NthWeekday
|
|
|
23
25
|
# @raise [ArgumentError] If parameters are invalid
|
|
24
26
|
def get(year:, month:, weekday:, nth:)
|
|
25
27
|
validate_params(year, month, weekday, nth)
|
|
26
|
-
|
|
28
|
+
|
|
27
29
|
wday = WEEKDAY_MAP[weekday.to_sym]
|
|
28
|
-
raise ArgumentError,
|
|
29
|
-
|
|
30
|
+
raise ArgumentError, 'Invalid weekday symbol' unless wday
|
|
31
|
+
|
|
30
32
|
first_day = Date.new(year, month, 1)
|
|
31
33
|
last_day = first_day.next_month.prev_day
|
|
32
|
-
|
|
34
|
+
|
|
33
35
|
days = (first_day..last_day).select { |date| date.wday == wday }
|
|
34
|
-
|
|
36
|
+
|
|
35
37
|
if nth == -1
|
|
36
38
|
days.last
|
|
37
39
|
else
|
|
38
40
|
days[nth - 1]
|
|
39
41
|
end
|
|
40
42
|
end
|
|
41
|
-
|
|
43
|
+
|
|
42
44
|
private
|
|
43
|
-
|
|
44
|
-
def validate_params(year, month,
|
|
45
|
-
raise ArgumentError, "Invalid year: #{year}" unless year.is_a?(Integer) && year
|
|
45
|
+
|
|
46
|
+
def validate_params(year, month, _weekday, nth)
|
|
47
|
+
raise ArgumentError, "Invalid year: #{year}" unless year.is_a?(Integer) && year.positive?
|
|
46
48
|
raise ArgumentError, "Invalid month: #{month}" unless month.is_a?(Integer) && month.between?(1, 12)
|
|
47
49
|
raise ArgumentError, "Invalid nth: #{nth}" unless nth.is_a?(Integer) && (nth.between?(1, 5) || nth == -1)
|
|
48
50
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: nth_weekday
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Yusuke Higasa
|
|
@@ -9,49 +9,7 @@ autorequire:
|
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
11
|
date: 2025-05-10 00:00:00.000000000 Z
|
|
12
|
-
dependencies:
|
|
13
|
-
- !ruby/object:Gem::Dependency
|
|
14
|
-
name: bundler
|
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
|
16
|
-
requirements:
|
|
17
|
-
- - "~>"
|
|
18
|
-
- !ruby/object:Gem::Version
|
|
19
|
-
version: '2.0'
|
|
20
|
-
type: :development
|
|
21
|
-
prerelease: false
|
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
-
requirements:
|
|
24
|
-
- - "~>"
|
|
25
|
-
- !ruby/object:Gem::Version
|
|
26
|
-
version: '2.0'
|
|
27
|
-
- !ruby/object:Gem::Dependency
|
|
28
|
-
name: rake
|
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
|
30
|
-
requirements:
|
|
31
|
-
- - "~>"
|
|
32
|
-
- !ruby/object:Gem::Version
|
|
33
|
-
version: '13.0'
|
|
34
|
-
type: :development
|
|
35
|
-
prerelease: false
|
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
-
requirements:
|
|
38
|
-
- - "~>"
|
|
39
|
-
- !ruby/object:Gem::Version
|
|
40
|
-
version: '13.0'
|
|
41
|
-
- !ruby/object:Gem::Dependency
|
|
42
|
-
name: rspec
|
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
|
44
|
-
requirements:
|
|
45
|
-
- - "~>"
|
|
46
|
-
- !ruby/object:Gem::Version
|
|
47
|
-
version: '3.0'
|
|
48
|
-
type: :development
|
|
49
|
-
prerelease: false
|
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
-
requirements:
|
|
52
|
-
- - "~>"
|
|
53
|
-
- !ruby/object:Gem::Version
|
|
54
|
-
version: '3.0'
|
|
12
|
+
dependencies: []
|
|
55
13
|
description: A lightweight Ruby library to get dates like "3rd Wednesday" or "last
|
|
56
14
|
Friday" from any given year and month. Rails-compatible and dependency-free.
|
|
57
15
|
email:
|