philiprehberger-pluralize 0.3.0 → 0.4.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6b6fc3d3282e7320753b6958d77d12d032363f99ffb107d059360ecc7770f762
4
- data.tar.gz: b319efef8cc4c6a2e5613047f4b11d108494838c1bd0be1d94cdef80b9b2399b
3
+ metadata.gz: 8ccd680cfc70bb7869e3485f9aa6d7b30f939a0f00242c64e995aea632c1c121
4
+ data.tar.gz: dd1445d596873472b69da3622dcac5e6386b4e5dc33f96be67d89033e46ba9c4
5
5
  SHA512:
6
- metadata.gz: 57c53612201fda89b18fb6c4849ede7903f9343dbc541d15a0c8e1c699b7acd0439e9c69545e87ce86503bf2fd956fe948c305a1e8970a20fd9f9e1346bdfdb2
7
- data.tar.gz: 9ca00bb43571356ec9fef5a5ad0cccc54fa0bc9bb5dc12149d6b59ef74747a330a36446d02920e0c05155856716c64a1c0eeaec2fe613728854ef930a2353cda
6
+ metadata.gz: 1d3cce73efa4291d0a59c8f905fd36c6e0daa765cc33cb54a03d80e460ec37ea9d86dbf0c0455c746979f58b53f7ad1791468d0014fb575eae22aa04f781a7d2
7
+ data.tar.gz: 708d560d47bd7a43d520334bed8229ccd3ec2a90fb11f06129915357115845580fb3a949fb8d8e011784e66f23955fe67c14357c3504a60d2f6025fe547f22f7
data/CHANGELOG.md CHANGED
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.4.0] - 2026-04-29
11
+
12
+ ### Added
13
+ - `Pluralize.indefinite_article(word, capitalize: false)` returning "a"/"an" with handling for silent-h words ("hour", "honest") and consonant-y-vowel words ("university", "unicorn")
14
+
10
15
  ## [0.3.0] - 2026-04-15
11
16
 
12
17
  ### Added
@@ -70,7 +75,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
70
75
  - Custom uncountable word registration
71
76
  - String inflections: camel_case, snake_case, titleize, humanize
72
77
 
73
- [Unreleased]: https://github.com/philiprehberger/rb-pluralize/compare/v0.3.0...HEAD
78
+ [Unreleased]: https://github.com/philiprehberger/rb-pluralize/compare/v0.4.0...HEAD
79
+ [0.4.0]: https://github.com/philiprehberger/rb-pluralize/compare/v0.3.0...v0.4.0
74
80
  [0.3.0]: https://github.com/philiprehberger/rb-pluralize/compare/v0.2.0...v0.3.0
75
81
  [0.2.0]: https://github.com/philiprehberger/rb-pluralize/compare/v0.1.6...v0.2.0
76
82
  [0.1.6]: https://github.com/philiprehberger/rb-pluralize/compare/v0.1.5...v0.1.6
data/README.md CHANGED
@@ -99,6 +99,15 @@ Philiprehberger::Pluralize.uncountable?('equipment') # => true
99
99
  Philiprehberger::Pluralize.uncountable?('cat') # => false
100
100
  ```
101
101
 
102
+ ### Indefinite Article
103
+
104
+ ```ruby
105
+ Philiprehberger::Pluralize.indefinite_article('apple') # => "an"
106
+ Philiprehberger::Pluralize.indefinite_article('university') # => "a"
107
+ Philiprehberger::Pluralize.indefinite_article('hour') # => "an"
108
+ Philiprehberger::Pluralize.indefinite_article('Apple', capitalize: true) # => "An"
109
+ ```
110
+
102
111
  ### Custom Irregular Words
103
112
 
104
113
  ```ruby
@@ -137,6 +146,7 @@ Philiprehberger::Pluralize.humanize('user_id') # => "User"
137
146
  | `Pluralize.count(n, word, style:)` | Format a count with singular/plural word (`:numeric` or `:words` style) |
138
147
  | `Pluralize.pluralize(n, singular, plural = nil)` | Rails-style: format a count with a required singular and optional explicit plural |
139
148
  | `Pluralize.capitalize_and_pluralize(word)` | Capitalize a word and return its plural form |
149
+ | `.indefinite_article(word, capitalize: false)` | Return "a" or "an" for `word`, with silent-h and consonant-y-vowel handling |
140
150
  | `Pluralize.uncountable?(word)` | Return true if the word is uncountable (built-in or custom) |
141
151
  | `Pluralize.irregular(singular, plural)` | Register a custom irregular singular/plural pair |
142
152
  | `Pluralize.uncountable(word)` | Register a word as uncountable |
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Philiprehberger
4
4
  module Pluralize
5
- VERSION = '0.3.0'
5
+ VERSION = '0.4.0'
6
6
  end
7
7
  end
@@ -224,8 +224,37 @@ module Philiprehberger
224
224
  @custom_uncountables = Set.new
225
225
  end
226
226
 
227
+ # Return the indefinite article ("a" or "an") for `word`.
228
+ #
229
+ # Handles vowel-letter prefixes, common silent-h words ("hour", "honest"),
230
+ # and consonant-y-vowel cases ("university", "unicorn").
231
+ #
232
+ # @param word [String] the noun the article precedes
233
+ # @param capitalize [Boolean] return "A"/"An" instead of "a"/"an"
234
+ # @return [String] "a", "an", "A", or "An"
235
+ # @raise [ArgumentError] when word is empty
236
+ def indefinite_article(word, capitalize: false)
237
+ raise ArgumentError, 'word must not be empty' if word.nil? || word.empty?
238
+
239
+ lower = word.downcase
240
+ article =
241
+ if SILENT_H_AN.any? { |w| lower.start_with?(w) }
242
+ 'an'
243
+ elsif CONSONANT_Y_VOWEL_A.any? { |w| lower.start_with?(w) }
244
+ 'a'
245
+ elsif %w[a e i o u].include?(lower[0])
246
+ 'an'
247
+ else
248
+ 'a'
249
+ end
250
+ capitalize ? article.capitalize : article
251
+ end
252
+
227
253
  private
228
254
 
255
+ SILENT_H_AN = %w[hour honest honor honour heir heirloom heirs herb].freeze
256
+ CONSONANT_Y_VOWEL_A = %w[universe university unicorn unique uniform united union user useful one once].freeze
257
+
229
258
  ORDINALS = {
230
259
  1 => 'first', 2 => 'second', 3 => 'third', 4 => 'fourth', 5 => 'fifth',
231
260
  6 => 'sixth', 7 => 'seventh', 8 => 'eighth', 9 => 'ninth', 10 => 'tenth',
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: philiprehberger-pluralize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philip Rehberger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-04-15 00:00:00.000000000 Z
11
+ date: 2026-04-29 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Pluralize and singularize English words without ActiveSupport. Includes
14
14
  200+ rules, irregular word handling, uncountable words, possessives, ordinals, plural