dry-inflector 1.2.0 → 1.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a29169ed905c202d9bb082e009642b814ad1b19e32c8915d94f16725e291e93f
4
- data.tar.gz: 4ed346b04b6f0330eb5cec81dca8e8ba3e77a80ddfe6ce3c29662be0413a7119
3
+ metadata.gz: 2e21e6bdd43527f9c443e40eaa1177af2effb59a4af5d4c092fa239e27c4171d
4
+ data.tar.gz: 915df3de975122d2c4fb19e8c95721fc4aa36955e7c98a915c5209bd0d6cde15
5
5
  SHA512:
6
- metadata.gz: 1f224fb42751e9df20caf821987c1595af1c3952090aad3163fb4357cd67b9376e1791ba6837551cf7d35f30aa3398fc7c4e69f8df7a3d36f6c801b9cf65479c
7
- data.tar.gz: 07b107dd66fee8bcb856139969223e35229997b934005a3e6a0b63d965326f90fc9f61e1585a0609e00b938987693dee009996358776328c107ce12b75f257ea
6
+ metadata.gz: b93d956d7915af3955c2e29af23dbd956b9a5d4cd9df7a9186f2057bd632647b8eb1166c03fd6aad9a51ab30c7cb6a9a5c752ba4f5644766a987f247f042df15
7
+ data.tar.gz: 61c8bbe11e7ef997079475d7d1b8ffe921064e0b5df7535a8248f1ab1837e05ea96b15ea76f63b1c20d7fe2f5a25c746425593e94e109bf9438f46f11420629b
data/CHANGELOG.md CHANGED
@@ -1,112 +1,153 @@
1
- <!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
1
+ # Changelog
2
2
 
3
- ## 1.2.0 2025-01-04
3
+ All notable changes to this project will be documented in this file.
4
4
 
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Break Versioning](https://www.taoensso.com/break-versioning).
7
+
8
+ ## [Unreleased]
9
+
10
+ ### Added
5
11
 
6
12
  ### Changed
7
13
 
8
- - Bumped required Ruby version to 3.1 (@flash-gordon)
14
+ ### Deprecated
9
15
 
10
- [Compare v1.1.0...v1.2.0](https://github.com/dry-rb/dry-inflector/compare/v1.1.0...v1.2.0)
16
+ ### Removed
11
17
 
12
- ## 1.1.0 2024-07-02
18
+ ### Fixed
13
19
 
20
+ ### Security
14
21
 
15
- ### Added
22
+ [Unreleased]: https://github.com/dry-rb/dry-inflector/compare/v1.3.1...main
16
23
 
17
- - Added "DB" as a default acronym (#49) (@timriley)
24
+ ## [1.3.1] - 2026-01-13
18
25
 
19
26
  ### Fixed
20
27
 
21
- - Fix incorrect inflections on words separated by spaces, underscores or hyphens (#47) (@parndt)
28
+ - Improve pluralization of "-um" vs "-ium" words. "Premium" is now pluralized correctly. (@hmaddocks in #60)
22
29
 
30
+ [1.3.1]: https://github.com/dry-rb/dry-inflector/compare/v1.3.0...v1.3.1
23
31
 
24
- [Compare v1.0.0...v1.1.0](https://github.com/dry-rb/dry-inflector/compare/v1.0.0...v1.1.0)
32
+ ## [1.3.0] - 2026-01-09
25
33
 
26
- ## 1.0.0 2022-11-04
34
+ ### Changed
27
35
 
36
+ - Require Ruby 3.2 or later. (@alassek)
37
+ - Support characters with diacritics. (@cllns in #51)
38
+ - Improve performance of #singularize. (@sandbergja in #53)
39
+ - Remove redundant regexps for default inflections. (@hmaddocks in #59)
28
40
 
29
- ### Changed
41
+ ### Fixed
42
+
43
+ - Correctly handle pluralized aconyms in `#underscore`. For example, underscoring "CustomerAPIs" now gives "customer_apis". (@hmaddocks in #54)
44
+ - Correctly singularize "uses" and pluralize "use". (@hmaddocks in #55)
45
+ - Fix singularization of plurals ending in a vowel and "xes", such as "taxes" -> "tax". (@hmaddocks in #56)
46
+ - Fix pluralization of words ending in "ee", such as "fee" -> "fees". (@hmaddocks in #57)
47
+ - Fix singularizing of words like "leaves" and "thieves". (@hmaddocks in #58)
48
+ - Fix pluralization of words ending in "f" that should _not_ have their ending turn into "ves", e.g. "roof"->"roofs" and "chief"->"chiefs". (@hmaddocks in #59)
49
+ - Fix pluralization of "virus" into "viruses". (@hmaddocks in #59)
30
50
 
31
- - Bumped version to 1.0.0 (@solnic)
51
+ [1.3.0]: https://github.com/dry-rb/dry-inflector/compare/v1.2.0...v1.3.0
32
52
 
33
- [Compare v0.3.0...v1.0.0](https://github.com/dry-rb/dry-inflector/compare/v0.3.0...v1.0.0)
53
+ ## [1.2.0] - 2025-01-04
34
54
 
35
- ## 0.3.0 2022-07-12
55
+ ### Changed
36
56
 
57
+ - Bumped required Ruby version to 3.1 (@flash-gordon)
58
+
59
+ [1.2.0]: https://github.com/dry-rb/dry-inflector/compare/v1.1.0...v1.2.0
60
+
61
+ ## [1.1.0] - 2024-07-02
37
62
 
38
63
  ### Added
39
64
 
40
- - Add CSV as default acronym (via #43) (@waiting-for-dev)
65
+ - Added "DB" as a default acronym. (@timriley in #49)
41
66
 
42
- ### Changed
67
+ ### Fixed
43
68
 
44
- - Extra dashes are now omitted when converting to camelcase (via #40) (@postmodern)
69
+ - Fix incorrect inflections on words separated by spaces, underscores or hyphens. (@parndt in #47)
45
70
 
46
- [Compare v0.2.1...v0.3.0](https://github.com/dry-rb/dry-inflector/compare/v0.2.1...v0.3.0)
71
+ [1.1.0]: https://github.com/dry-rb/dry-inflector/compare/v1.0.0...v1.1.0
47
72
 
48
- ## 0.2.1 2021-06-30
73
+ ## [1.0.0] - 2022-11-04
49
74
 
75
+ ### Changed
50
76
 
51
- ### Added
77
+ - Bumped version to 1.0.0. (@solnic)
52
78
 
53
- - Add default acronyms: API and CSRF (#35) (@jodosha)
79
+ [1.0.0]: https://github.com/dry-rb/dry-inflector/compare/v0.3.0...v1.0.0
54
80
 
55
- ### Fixed
81
+ ## [0.3.0] - 2022-07-12
56
82
 
57
- - Fix singularizing -us suffix (issue #33 via #38) (@cllns)
83
+ ### Added
84
+
85
+ - Add CSV as default acronym. (@waiting-for-dev in #43)
58
86
 
87
+ ### Changed
59
88
 
60
- [Compare v0.2.0...v0.2.1](https://github.com/dry-rb/dry-inflector/compare/v0.2.0...v0.2.1)
89
+ - Extra dashes are now omitted when converting to camelcase. (@postmodern in #40)
61
90
 
62
- ## 0.2.0 2019-10-13
91
+ [0.3.0]: https://github.com/dry-rb/dry-inflector/compare/v0.2.1...v0.3.0
63
92
 
93
+ ## [0.2.1] - 2021-06-30
64
94
 
65
95
  ### Added
66
96
 
67
- - [Abinoam P. Marques Jr. & Andrii Savchenko] Introduced `Dry::Inflector#camelize_upper` and `Dry::Inflector#camelize_lower`. `Dry::Inflector#camelize` is now an alias for `Dry::Inflector#camelize_upper`. ```ruby inflector.camelize_upper("data_mapper") # => "DataMapper"' inflector.camelize_lower("data_mapper") # => "dataMapper"' ```
97
+ - Add default acronyms: API and CSRF. (@jodosha in #35)
68
98
 
69
99
  ### Fixed
70
100
 
71
- - [ecnal] Fixed singularization rules for words like "alias" or "status"
101
+ - Fix singularizing -us suffix. (@cllns in #38)
72
102
 
103
+ [0.2.1]: https://github.com/dry-rb/dry-inflector/compare/v0.2.0...v0.2.1
73
104
 
74
- [Compare v0.1.2...v0.2.0](https://github.com/dry-rb/dry-inflector/compare/v0.1.2...v0.2.0)
105
+ ## [0.2.0] - 2019-10-13
75
106
 
76
- ## 0.1.2 2018-04-25
107
+ ### Added
77
108
 
109
+ - Introduced `Dry::Inflector#camelize_upper` and `Dry::Inflector#camelize_lower`. `Dry::Inflector#camelize` is now an alias for `Dry::Inflector#camelize_upper`. (Abinoam P. Marques Jr. & Andrii Savchenko)
78
110
 
79
- ### Added
111
+ ```ruby
112
+ inflector.camelize_upper("data_mapper") # => "DataMapper"
113
+ inflector.camelize_lower("data_mapper") # => "dataMapper"
114
+ ```
80
115
 
81
- - [Gustavo Caso & Nikita Shilnikov] Added support for acronyms
116
+ ### Fixed
82
117
 
118
+ - Fixed singularization rules for words like "alias" or "status". (ecnal)
83
119
 
84
- [Compare v0.1.1...v0.1.2](https://github.com/dry-rb/dry-inflector/compare/v0.1.1...v0.1.2)
120
+ [0.2.0]: https://github.com/dry-rb/dry-inflector/compare/v0.1.2...v0.2.0
85
121
 
86
- ## 0.1.1 2017-11-18
122
+ ## [0.1.2] - 2018-04-25
87
123
 
124
+ ### Added
88
125
 
89
- ### Fixed
126
+ - Added support for acronyms. (Gustavo Caso & Nikita Shilnikov)
127
+
128
+ [0.1.2]: https://github.com/dry-rb/dry-inflector/compare/v0.1.1...v0.1.2
90
129
 
91
- - [Luca Guidi & Abinoam P. Marques Jr.] Ensure `Dry::Inflector#ordinalize` to work for all the numbers from 0 to 100
130
+ ## [0.1.1] - 2017-11-18
92
131
 
132
+ ### Fixed
93
133
 
94
- [Compare v0.1.0...v0.1.1](https://github.com/dry-rb/dry-inflector/compare/v0.1.0...v0.1.1)
134
+ - Ensure `Dry::Inflector#ordinalize` to work for all the numbers from 0 to 100. (Luca Guidi & Abinoam P. Marques Jr.)
95
135
 
96
- ## 0.1.0 2017-11-17
136
+ [0.1.1]: https://github.com/dry-rb/dry-inflector/compare/v0.1.0...v0.1.1
97
137
 
138
+ ## [0.1.0] - 2017-11-17
98
139
 
99
140
  ### Added
100
141
 
101
- - [Luca Guidi] Introduced `Dry::Inflector#pluralize`
102
- - [Luca Guidi] Introduced `Dry::Inflector#singularize`
103
- - [Luca Guidi] Introduced `Dry::Inflector#camelize`
104
- - [Luca Guidi] Introduced `Dry::Inflector#classify`
105
- - [Luca Guidi] Introduced `Dry::Inflector#tableize`
106
- - [Luca Guidi] Introduced `Dry::Inflector#dasherize`
107
- - [Luca Guidi] Introduced `Dry::Inflector#underscore`
108
- - [Luca Guidi] Introduced `Dry::Inflector#demodulize`
109
- - [Luca Guidi] Introduced `Dry::Inflector#humanize`
110
- - [Luca Guidi] Introduced `Dry::Inflector#ordinalize`
111
- - [Abinoam P. Marques Jr.] Introduced `Dry::Inflector#foreign_key`
112
- - [Abinoam P. Marques Jr.] Introduced `Dry::Inflector#constantize`
142
+ - Introduced `Dry::Inflector#pluralize`. (Luca Guidi)
143
+ - Introduced `Dry::Inflector#singularize`. (Luca Guidi)
144
+ - Introduced `Dry::Inflector#camelize`. (Luca Guidi)
145
+ - Introduced `Dry::Inflector#classify`. (Luca Guidi)
146
+ - Introduced `Dry::Inflector#tableize`. (Luca Guidi)
147
+ - Introduced `Dry::Inflector#dasherize`. (Luca Guidi)
148
+ - Introduced `Dry::Inflector#underscore`. (Luca Guidi)
149
+ - Introduced `Dry::Inflector#demodulize`. (Luca Guidi)
150
+ - Introduced `Dry::Inflector#humanize`. (Luca Guidi)
151
+ - Introduced `Dry::Inflector#ordinalize`. (Luca Guidi)
152
+ - Introduced `Dry::Inflector#foreign_key`. (Abinoam P. Marques Jr.)
153
+ - Introduced `Dry::Inflector#constantize`. (Abinoam P. Marques Jr.)
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015-2023 dry-rb team
3
+ Copyright (c) 2015-2026 Hanakai team
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of
6
6
  this software and associated documentation files (the "Software"), to deal in
data/README.md CHANGED
@@ -1,22 +1,17 @@
1
- <!--- this file is synced from dry-rb/template-gem project -->
2
- [gem]: https://rubygems.org/gems/dry-inflector
1
+ <!--- This file is synced from hanakai-rb/repo-sync -->
2
+
3
+ [rubygem]: https://rubygems.org/gems/dry-inflector
3
4
  [actions]: https://github.com/dry-rb/dry-inflector/actions
4
5
 
5
- # dry-inflector [![Gem Version](https://badge.fury.io/rb/dry-inflector.svg)][gem] [![CI Status](https://github.com/dry-rb/dry-inflector/workflows/ci/badge.svg)][actions]
6
+ # dry-inflector [![Gem Version](https://badge.fury.io/rb/dry-inflector.svg)][rubygem] [![CI Status](https://github.com/dry-rb/dry-inflector/workflows/CI/badge.svg)][actions]
6
7
 
7
8
  ## Links
8
9
 
9
- * [User documentation](https://dry-rb.org/gems/dry-inflector)
10
- * [API documentation](http://rubydoc.info/gems/dry-inflector)
11
- * [Forum](https://discourse.dry-rb.org)
12
-
13
- ## Supported Ruby versions
14
-
15
- This library officially supports the following Ruby versions:
16
-
17
- * MRI `>= 3.0.0`
18
- * jruby `>= 9.4` (not tested on CI)
10
+ - [User documentation](https://dry-rb.org/gems/dry-inflector)
11
+ - [API documentation](http://rubydoc.info/gems/dry-inflector)
12
+ - [Forum](https://discourse.dry-rb.org)
19
13
 
20
14
  ## License
21
15
 
22
16
  See `LICENSE` file.
17
+
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # this file is synced from dry-rb/template-gem project
3
+ # This file is synced from hanakai-rb/repo-sync. To update it, edit repo-sync.yml.
4
4
 
5
5
  lib = File.expand_path("lib", __dir__)
6
6
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
@@ -8,25 +8,31 @@ require "dry/inflector/version"
8
8
 
9
9
  Gem::Specification.new do |spec|
10
10
  spec.name = "dry-inflector"
11
- spec.authors = ["Luca Guidi", "Andrii Savchenko", "Abinoam P. Marques Jr."]
12
- spec.email = ["me@lucaguidi.com", "andrey@aejis.eu", "abinoam@gmail.com"]
11
+ spec.authors = ["Hanakai team"]
12
+ spec.email = ["info@hanakai.org"]
13
13
  spec.license = "MIT"
14
14
  spec.version = Dry::Inflector::VERSION.dup
15
15
 
16
16
  spec.summary = "String inflections for dry-rb"
17
17
  spec.description = spec.summary
18
18
  spec.homepage = "https://dry-rb.org/gems/dry-inflector"
19
- spec.files = Dir["CHANGELOG.md", "LICENSE", "README.md", "dry-inflector.gemspec",
20
- "lib/**/*"]
19
+ spec.files = Dir["CHANGELOG.md", "LICENSE", "README.md", "dry-inflector.gemspec", "lib/**/*"]
21
20
  spec.bindir = "bin"
22
21
  spec.executables = []
23
22
  spec.require_paths = ["lib"]
24
23
 
25
- spec.metadata["allowed_push_host"] = "https://rubygems.org"
26
- spec.metadata["changelog_uri"] = "https://github.com/dry-rb/dry-inflector/blob/main/CHANGELOG.md"
27
- spec.metadata["source_code_uri"] = "https://github.com/dry-rb/dry-inflector"
28
- spec.metadata["bug_tracker_uri"] = "https://github.com/dry-rb/dry-inflector/issues"
29
- spec.metadata["rubygems_mfa_required"] = "true"
24
+ spec.extra_rdoc_files = ["README.md", "CHANGELOG.md", "LICENSE"]
30
25
 
31
- spec.required_ruby_version = ">= 3.1"
26
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
27
+ spec.metadata["changelog_uri"] = "https://github.com/dry-rb/dry-inflector/blob/main/CHANGELOG.md"
28
+ spec.metadata["source_code_uri"] = "https://github.com/dry-rb/dry-inflector"
29
+ spec.metadata["bug_tracker_uri"] = "https://github.com/dry-rb/dry-inflector/issues"
30
+ spec.metadata["funding_uri"] = "https://github.com/sponsors/hanami"
31
+
32
+ spec.required_ruby_version = ">= 3.2"
33
+
34
+ spec.add_development_dependency "bundler"
35
+ spec.add_development_dependency "rake"
36
+ spec.add_development_dependency "rspec"
32
37
  end
38
+
@@ -27,23 +27,21 @@ module Dry
27
27
  inflect.plural(/s\z/i, "s")
28
28
  inflect.plural(/(ax|test)is\z/i, '\1es')
29
29
  inflect.plural(/(.*)us\z/i, '\1uses')
30
- inflect.plural(/(octop|vir|cact)us\z/i, '\1i')
31
- inflect.plural(/(octop|vir)i\z/i, '\1i')
30
+ inflect.plural(/(octop|cact)us\z/i, '\1i')
32
31
  inflect.plural(/(alias|status)\z/i, '\1es')
33
32
  inflect.plural(/(buffal|domin|ech|embarg|her|mosquit|potat|tomat)o\z/i, '\1oes')
34
- inflect.plural(/(?<!b)um\z/i, '\1a')
33
+ inflect.plural(/(?<!b|for)um\z/i, "a")
34
+ inflect.plural(/(premi|.*[aio]ni|.*ori|.*ari|.*[no]di|.*[pt]i|.*si)um\z/i, '\1ums')
35
35
  inflect.plural(/([ti])a\z/i, '\1a')
36
36
  inflect.plural(/sis\z/i, "ses")
37
- inflect.plural(/(.*)(?:([^f]))fe*\z/i, '\1\2ves')
38
- inflect.plural(/(hive|proof)\z/i, '\1s') # TODO: proof can be moved in the above regexp
37
+ inflect.plural(/(.*)(?:([^f]))fe?\z/i, '\1\2ves')
38
+ inflect.plural(/(roof|chief|ee|hive|proof)\z/i, '\1s')
39
39
  inflect.plural(/([^aeiouy]|qu)y\z/i, '\1ies')
40
40
  inflect.plural(/(x|ch|ss|sh)\z/i, '\1es')
41
41
  inflect.plural(/(stoma|epo)ch\z/i, '\1chs')
42
42
  inflect.plural(/(matr|vert|ind)(?:ix|ex)\z/i, '\1ices')
43
- inflect.plural(/([m|l])ouse\z/i, '\1ice')
44
- inflect.plural(/([m|l])ice\z/i, '\1ice')
43
+ inflect.plural(/([ml])ouse\z/i, '\1ice')
45
44
  inflect.plural(/^(ox)\z/i, '\1en')
46
- inflect.plural(/^(oxen)\z/i, '\1')
47
45
  inflect.plural(/(quiz)\z/i, '\1zes')
48
46
  inflect.plural(/(.*)non\z/i, '\1na')
49
47
  inflect.plural(/(.*)ma\z/i, '\1mata')
@@ -60,26 +58,30 @@ module Dry
60
58
  '\1\2sis')
61
59
  inflect.singular(/(^analy)(sis|ses)\z/i, '\1sis')
62
60
  inflect.singular(/([^f])ves\z/i, '\1fe')
61
+ inflect.singular(/([lr])ves\z/i, '\1f')
62
+ inflect.singular(/(ea)ves\z/i, '\1f')
63
+ inflect.singular(/(ie)ves\z/i, '\1f')
63
64
  inflect.singular(/(hive)s\z/i, '\1')
64
65
  inflect.singular(/(tive)s\z/i, '\1')
65
- inflect.singular(/([lr])ves\z/i, '\1f')
66
66
  inflect.singular(/([^aeiouy]|qu)ies\z/i, '\1y')
67
67
  inflect.singular(/(s)eries\z/i, '\1eries')
68
68
  inflect.singular(/(m)ovies\z/i, '\1ovie')
69
69
  inflect.singular(/(ss)\z/i, '\1')
70
70
  inflect.singular(/(x|ch|ss|sh)es\z/i, '\1')
71
- inflect.singular(/([m|l])ice\z/i, '\1ouse')
72
- inflect.singular(/(us)(es)?\z/i, '\1')
71
+ inflect.singular(/([ml])ice\z/i, '\1ouse')
72
+ inflect.singular(/(us)(?:es)?\z/i, '\1')
73
+ inflect.singular(/(\b|_|-)([eou])ses\z/i, '\1\2se')
73
74
  inflect.singular(/(o)es\z/i, '\1')
74
75
  inflect.singular(/(shoe)s\z/i, '\1')
75
- inflect.singular(/(cris|ax|test)(is|es)\z/i, '\1is')
76
- inflect.singular(/(octop|vir)(us|i)\z/i, '\1us')
77
- inflect.singular(/(alias|status)(es)?\z/i, '\1')
76
+ inflect.singular(/(cris|ax|test)(?:is|es)\z/i, '\1is')
77
+ inflect.singular(/(octop|vir)(?:us|i)\z/i, '\1us')
78
+ inflect.singular(/(alias|status)(?:es)?\z/i, '\1')
78
79
  inflect.singular(/(ox)en/i, '\1')
79
80
  inflect.singular(/(vert|ind)ices\z/i, '\1ex')
80
81
  inflect.singular(/(matr)ices\z/i, '\1ix')
81
82
  inflect.singular(/(quiz)zes\z/i, '\1')
82
83
  inflect.singular(/(database)s\z/i, '\1')
84
+ inflect.singular(/([a-hj-z][aeiou])xes\z/i, '\1x')
83
85
  end
84
86
 
85
87
  # @since 0.1.0
@@ -95,9 +97,6 @@ module Dry
95
97
  inflect.irregular("foot", "feet")
96
98
  inflect.irregular("tooth", "teeth")
97
99
  inflect.irregular("goose", "geese")
98
-
99
- # FIXME: this is here because I need to fix the "um" regexp
100
- inflect.irregular("forum", "forums")
101
100
  end
102
101
 
103
102
  # @since 0.1.0
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "set"
4
3
  require "dry/inflector/rules"
5
4
  require "dry/inflector/acronyms"
6
5
 
@@ -16,9 +16,12 @@ module Dry
16
16
  # @since 0.1.0
17
17
  # @api private
18
18
  def apply_to(word)
19
- result = word.dup
20
- each { |rule, replacement| break if result.gsub!(rule, replacement) }
21
- result
19
+ matching_rule = @rules.find { |rule, _replacement| rule.match? word }
20
+ if matching_rule
21
+ word.gsub(matching_rule[0], matching_rule[1])
22
+ else
23
+ word
24
+ end.dup
22
25
  end
23
26
 
24
27
  # @since 0.1.0
@@ -26,12 +29,6 @@ module Dry
26
29
  def insert(index, array)
27
30
  @rules.insert(index, array)
28
31
  end
29
-
30
- # @since 0.1.0
31
- # @api private
32
- def each(&)
33
- @rules.each(&)
34
- end
35
32
  end
36
33
  end
37
34
  end
@@ -3,6 +3,6 @@
3
3
  module Dry
4
4
  class Inflector
5
5
  # @since 0.1.0
6
- VERSION = "1.2.0"
6
+ VERSION = "1.3.1"
7
7
  end
8
8
  end
data/lib/dry/inflector.rb CHANGED
@@ -155,7 +155,7 @@ module Dry
155
155
  result = inflections.humans.apply_to(input)
156
156
  result.delete_suffix!("_id")
157
157
  result.tr!("_", " ")
158
- match = /(\W)/.match(result)
158
+ match = /([^[:alnum:]])/.match(result)
159
159
  separator = match ? match[0] : DEFAULT_SEPARATOR
160
160
  result.split(separator).map.with_index { |word, index|
161
161
  inflections.acronyms.apply_to(word, capitalize: index.zero?)
@@ -283,8 +283,8 @@ module Dry
283
283
  m2 = Regexp.last_match(2)
284
284
  "#{m1 ? "_" : ""}#{m2.downcase}"
285
285
  end
286
- input.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
287
- input.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
286
+ input.gsub!(/([[:upper:][:digit:]]+)([[:upper:]][[:lower:]])(?=[[:lower:]])/, '\1_\2')
287
+ input.gsub!(/([[:lower:][:digit:]])([[:upper:]])/, '\1_\2')
288
288
  input.tr!("-", "_")
289
289
  input.downcase!
290
290
  input
@@ -300,7 +300,7 @@ module Dry
300
300
  def uncountable?(input)
301
301
  input.match?(/\A[[:space:]]*\z/) ||
302
302
  inflections.uncountables.include?(input.downcase) ||
303
- inflections.uncountables.include?(input.split(/_|\b/).last.downcase)
303
+ inflections.uncountables.include?(input.rpartition(/_|\b(?!\z)/).last.downcase)
304
304
  end
305
305
 
306
306
  # @return [String]
@@ -328,8 +328,10 @@ module Dry
328
328
  # @api private
329
329
  def internal_camelize(input, upper)
330
330
  input = input.to_s.dup
331
- input.sub!(/^[a-z\d]*/) { |match| inflections.acronyms.apply_to(match, capitalize: upper) }
332
- input.gsub!(%r{(?:[_-]|(/))([a-z\d]*)}i) do
331
+ input.sub!(/^[[:lower:][:digit:]]*/) do |match|
332
+ inflections.acronyms.apply_to(match, capitalize: upper)
333
+ end
334
+ input.gsub!(%r{(?:[_-]|(/))([[:lower:][:digit:]]*)}i) do
333
335
  m1 = Regexp.last_match(1)
334
336
  m2 = Regexp.last_match(2)
335
337
  "#{m1}#{inflections.acronyms.apply_to(m2)}"
metadata CHANGED
@@ -1,25 +1,65 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-inflector
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
- - Luca Guidi
8
- - Andrii Savchenko
9
- - Abinoam P. Marques Jr.
10
- autorequire:
7
+ - Hanakai team
11
8
  bindir: bin
12
9
  cert_chain: []
13
- date: 2025-01-04 00:00:00.000000000 Z
14
- dependencies: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: bundler
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :development
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: rake
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ - !ruby/object:Gem::Dependency
41
+ name: rspec
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
15
54
  description: String inflections for dry-rb
16
55
  email:
17
- - me@lucaguidi.com
18
- - andrey@aejis.eu
19
- - abinoam@gmail.com
56
+ - info@hanakai.org
20
57
  executables: []
21
58
  extensions: []
22
- extra_rdoc_files: []
59
+ extra_rdoc_files:
60
+ - CHANGELOG.md
61
+ - LICENSE
62
+ - README.md
23
63
  files:
24
64
  - CHANGELOG.md
25
65
  - LICENSE
@@ -40,8 +80,7 @@ metadata:
40
80
  changelog_uri: https://github.com/dry-rb/dry-inflector/blob/main/CHANGELOG.md
41
81
  source_code_uri: https://github.com/dry-rb/dry-inflector
42
82
  bug_tracker_uri: https://github.com/dry-rb/dry-inflector/issues
43
- rubygems_mfa_required: 'true'
44
- post_install_message:
83
+ funding_uri: https://github.com/sponsors/hanami
45
84
  rdoc_options: []
46
85
  require_paths:
47
86
  - lib
@@ -49,15 +88,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
49
88
  requirements:
50
89
  - - ">="
51
90
  - !ruby/object:Gem::Version
52
- version: '3.1'
91
+ version: '3.2'
53
92
  required_rubygems_version: !ruby/object:Gem::Requirement
54
93
  requirements:
55
94
  - - ">="
56
95
  - !ruby/object:Gem::Version
57
96
  version: '0'
58
97
  requirements: []
59
- rubygems_version: 3.3.27
60
- signing_key:
98
+ rubygems_version: 3.6.9
61
99
  specification_version: 4
62
100
  summary: String inflections for dry-rb
63
101
  test_files: []