nth_weekday 0.1.1 → 0.2.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 (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +64 -7
  3. data/VERSION +1 -1
  4. data/lib/nth_weekday.rb +25 -9
  5. metadata +3 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 17898431f95d95110a7939d73ecdfb186d6316cafb2e8fe193ed8d7ba4cf1f51
4
- data.tar.gz: 52099f02ab6e904e90d234135f17d1782b43c5999bf86dbbf5878d7caa7951de
3
+ metadata.gz: e28ea963f943f3e81ebc4875aae5e1fd589e59ccb0805255e32b9e56aa33548b
4
+ data.tar.gz: adb591ba5a6e1438f514631081414236e94eb10ef86cc1b76fb87a12b92abed8
5
5
  SHA512:
6
- metadata.gz: 209ded1597fb87f51fc2752c1c768244ca8d5fda78ba6ecf1a52caf4583587e1d63121e953f8fe7fb38af227231934dd41c7597628930840cc1a6dae4e0000c4
7
- data.tar.gz: 01260b0b375215f8dfb920f41deda20446273e9015b3542177bb79f117cbd7f38755beb813f03e19797023570a0adb5e6553048d070f3b8c56e1a80beb803672
6
+ metadata.gz: 9ced69b3dc9394c73dae6ce531cc2946e0cec722d6f049abf5f33cd36c12e11dce1da87475243fa38e77e7d3bf08f509c66162e85e0e247f100ec340c6076d58
7
+ data.tar.gz: 9c5ecc75f439b0c174d87afd85defa3f8b70d35ef999c950830ab76c47a83439d19c4f103b897242767c9911fde974c52387849805c61f862645f510f729d266
data/README.md CHANGED
@@ -19,7 +19,6 @@
19
19
  - ✅ Rails / Sinatra / CLI / バッチ対応
20
20
  - 🧪 テスト済み、CI/CD導入しやすい構成
21
21
 
22
-
23
22
  ## 💎 Installation / インストール
24
23
 
25
24
  ```bash
@@ -33,6 +32,7 @@ gem install nth_weekday
33
32
  ## 💻 Requirements / 動作環境
34
33
 
35
34
  - Ruby 3.3.0以上
35
+ - CI verified on Ruby 3.3.0 and Ruby 4.0.1
36
36
 
37
37
  ## 🚀 Usage / 使い方
38
38
 
@@ -46,16 +46,27 @@ NthWeekday.get(year: 2025, month: 4, weekday: :we, nth: 3)
46
46
  # 最後の金曜日(2025年12月)
47
47
  NthWeekday.get(year: 2025, month: 12, weekday: :fr, nth: -1)
48
48
  # => #<Date: 2025-12-26>
49
+
50
+ # 日付文字列として取得
51
+ NthWeekday.get(year: 2025, month: 4, weekday: :we, nth: 3, format: '%Y-%m-%d')
52
+ # => "2025-04-16"
53
+
54
+ # UNIXタイムスタンプとして取得(UTC 00:00:00基準)
55
+ NthWeekday.get(year: 2025, month: 4, weekday: :we, nth: 3, format: :unix)
56
+ # => 1744761600
49
57
  ```
50
58
 
51
59
  ## 📘 Parameters / パラメータ
52
60
 
53
- | パラメータ名 | 型 | 説明 |
54
- |--------------|--------|-------------------------------------------------------|
55
- | `year` | Integer| 対象年(例: 2025) |
56
- | `month` | Integer| 対象月(1〜12) |
57
- | `weekday` | Symbol | 対象曜日(`:su`, `:mo`, `:tu`, `:we`, `:th`, `:fr`, `:sa`) |
58
- | `nth` | Integer| 第n◯曜日。1〜5、または `-1` で「最後の◯曜日」を指定 |
61
+ | パラメータ名 | 型 | 説明 |
62
+ |--------------|-----------------------|-------------------------------------------------------|
63
+ | `year` | Integer | 対象年(例: 2025) |
64
+ | `month` | Integer | 対象月(1〜12) |
65
+ | `weekday` | Symbol | 対象曜日(`:su`, `:mo`, `:tu`, `:we`, `:th`, `:fr`, `:sa`) |
66
+ | `nth` | Integer | 第n◯曜日。1〜5、または `-1` で「最後の◯曜日」を指定 |
67
+ | `format` | String, Symbol, nil | 省略可。`String` は `Date#strftime` 形式、`:unix` は UTC 00:00:00 基準の UNIX タイムスタンプ |
68
+
69
+ `format` を省略した場合は、従来通り `Date` オブジェクトを返します。
59
70
 
60
71
  ### 曜日シンボル一覧
61
72
  - `:su` - 日曜日 (Sunday)
@@ -87,6 +98,52 @@ bundle exec rubocop # コードスタイルチェック
87
98
 
88
99
  このプロジェクトでは [RuboCop](https://rubocop.org/) を使用してコードスタイルを一貫して維持しています。コード変更時は `bundle exec rubocop` でスタイルチェックを実行してください。
89
100
 
101
+ エージェント運用時のルールは以下を参照してください。
102
+
103
+ ## 🤖 AI / Agent Development Modes
104
+
105
+ このリポジトリは AI エージェントによる開発を前提に、2つのモードをサポートしています。
106
+
107
+ ### 🧩 通常モード(Single Agent)
108
+
109
+ 単一エージェントによる高速な実装。
110
+
111
+ **用途**
112
+ - 小規模修正
113
+ - 明確なタスク
114
+
115
+ ---
116
+
117
+ ### 🧠 オーケストレーターモード(Multi-Agent)
118
+
119
+ 複数の役割エージェントによる段階的開発。
120
+
121
+ **フロー**
122
+ 1. Issue
123
+ 2. Plan
124
+ 3. Implementation
125
+ 4. Review
126
+ 5. PR
127
+
128
+ **用途**
129
+ - 複雑な変更
130
+ - 設計が必要なタスク
131
+
132
+ ## 🧭 Mode Selection
133
+
134
+ | ケース | モード |
135
+ | :-- |:-- |
136
+ | 小規模な変更・新規機能 | 通常 |
137
+ | 複雑な変更・大規模な新規機能 | オーケストレーター |
138
+
139
+ ---
140
+
141
+ ## 📚 Docs
142
+
143
+ - [AGENTS.md](./AGENTS.md)
144
+ - [CODING_RULES.md](./CODING_RULES.md)
145
+ - [HUMAN_IN_THE_LOOP.md](./HUMAN_IN_THE_LOOP.md)
146
+
90
147
  ## 👥 Contributing / 貢献
91
148
 
92
149
  1. Fork the repository
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.0
data/lib/nth_weekday.rb CHANGED
@@ -21,10 +21,11 @@ module NthWeekday
21
21
  # @param month [Integer] Month (1-12)
22
22
  # @param weekday [Symbol] Weekday symbol (:mo, :tu, :we, :th, :fr, :sa, :su)
23
23
  # @param nth [Integer] The occurrence of the weekday (1-5, or -1 for last occurrence)
24
- # @return [Date] Date object representing the requested day
24
+ # @param format [String, Symbol, nil] Optional output format. String uses Date#strftime, :unix returns UTC midnight timestamp.
25
+ # @return [Date, String, Integer, nil] Date object, formatted string, UNIX timestamp, or nil when no matching date exists
25
26
  # @raise [ArgumentError] If parameters are invalid
26
- def get(year:, month:, weekday:, nth:)
27
- validate_params(year, month, weekday, nth)
27
+ def get(year:, month:, weekday:, nth:, format: nil)
28
+ validate_params(year, month, weekday, nth, format)
28
29
 
29
30
  wday = WEEKDAY_MAP[weekday.to_sym]
30
31
  raise ArgumentError, 'Invalid weekday symbol' unless wday
@@ -34,19 +35,34 @@ module NthWeekday
34
35
 
35
36
  days = (first_day..last_day).select { |date| date.wday == wday }
36
37
 
37
- if nth == -1
38
- days.last
39
- else
40
- days[nth - 1]
41
- end
38
+ date = if nth == -1
39
+ days.last
40
+ else
41
+ days[nth - 1]
42
+ end
43
+
44
+ format_date(date, format)
42
45
  end
43
46
 
44
47
  private
45
48
 
46
- def validate_params(year, month, _weekday, nth)
49
+ def validate_params(year, month, _weekday, nth, format)
47
50
  raise ArgumentError, "Invalid year: #{year}" unless year.is_a?(Integer) && year.positive?
48
51
  raise ArgumentError, "Invalid month: #{month}" unless month.is_a?(Integer) && month.between?(1, 12)
49
52
  raise ArgumentError, "Invalid nth: #{nth}" unless nth.is_a?(Integer) && (nth.between?(1, 5) || nth == -1)
53
+ raise ArgumentError, "Invalid format: #{format}" unless valid_format?(format)
54
+ end
55
+
56
+ def valid_format?(format)
57
+ format.nil? || format.is_a?(String) || format == :unix
58
+ end
59
+
60
+ def format_date(date, format)
61
+ return nil if date.nil?
62
+ return date if format.nil?
63
+ return Time.utc(date.year, date.month, date.day).to_i if format == :unix
64
+
65
+ date.strftime(format)
50
66
  end
51
67
  end
52
68
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nth_weekday
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yusuke Higasa
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2025-05-10 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies: []
13
12
  description: A lightweight Ruby library to get dates like "3rd Wednesday" or "last
14
13
  Friday" from any given year and month. Rails-compatible and dependency-free.
@@ -34,7 +33,6 @@ metadata:
34
33
  changelog_uri: https://github.com/yusukehigasa/nth_weekday/blob/main/CHANGELOG.md
35
34
  bug_tracker_uri: https://github.com/yusukehigasa/nth_weekday/issues
36
35
  rubygems_mfa_required: 'true'
37
- post_install_message:
38
36
  rdoc_options: []
39
37
  require_paths:
40
38
  - lib
@@ -49,8 +47,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
49
47
  - !ruby/object:Gem::Version
50
48
  version: '0'
51
49
  requirements: []
52
- rubygems_version: 3.5.16
53
- signing_key:
50
+ rubygems_version: 4.0.3
54
51
  specification_version: 4
55
52
  summary: Get dates like "3rd Wednesday" or "last Friday" from any given year and month
56
53
  test_files: []