dry-inflector 0.1.2 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7cccc4cd092473c4c5dfefd8830e97c987fbb6cd6039b6253fd973a0b4d5b8ac
4
- data.tar.gz: 6aca715e9ab5497c0f325691783e92a10035b27a3e6fdf483df38b7fb306d6ad
3
+ metadata.gz: 6db17e7fbcdc21a6c06f9763e9267d78045ffa2772272cd93abfc22d54ae80a2
4
+ data.tar.gz: bd47f925d3d558782192d3ce47cde9c9fb059163967a975e5d6298cd527e9912
5
5
  SHA512:
6
- metadata.gz: 2c9c21e1611fe3bafd8cf7e303b5030c1ba3f777fd397a58f2dfba77f8be05b49fdece384e49d82d43043e388ca3fc1f1c6c84508fdfdac02ce9851edfee1dba
7
- data.tar.gz: c83c9d597c611194642fe6aed04b3c5f6e37ec9fa212b3501a13c93010305f9c339875a09ba123b8a97fa89f567e90c110af9ac76317f4c16749a5e91601b57e
6
+ metadata.gz: b97888420794db32aa69dbad0b168089a4be99d1c68f7411cefeabba1027e42d1f161147af435740e775ee6836dd5a48dad981c0f825b430c77c3e7eeade8091
7
+ data.tar.gz: bf81663b753f1e370d4c8c8b84c844de54a7fce16613e8acbc8a0dcfc7302391f8a92edd51cdfb73fd163215aec9ff65db324d28b7df479a102b3f223ac64573
data/CHANGELOG.md CHANGED
@@ -1,23 +1,58 @@
1
- # Dry::Inflector
1
+ <!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
2
2
 
3
- Inflector for Ruby
3
+ ## unreleased
4
+
5
+
6
+ ### Fixed
7
+
8
+ - Fix singularizing -us suffix (issue #33 via #38) (@cllns)
9
+
10
+
11
+ [Compare v0.2.0...master](https://github.com/dry-rb/dry-inflector/compare/v0.2.0...master)
12
+
13
+ ## 0.2.0 2019-10-13
14
+
15
+
16
+ ### Added
17
+
18
+ - [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`.
19
+ - ```ruby
20
+ - inflector.camelize_upper("data_mapper") # => "DataMapper"
21
+ - inflector.camelize_lower("data_mapper") # => "dataMapper"
22
+ - ```
23
+
24
+ ### Fixed
25
+
26
+ - [ecnal] Fixed singularization rules for words like "alias" or "status"
27
+
28
+
29
+ [Compare v0.1.2...v0.2.0](https://github.com/dry-rb/dry-inflector/compare/v0.1.2...v0.2.0)
30
+
31
+ ## 0.1.2 2018-04-25
4
32
 
5
- ## v0.1.2 - to be released
6
33
 
7
34
  ### Added
8
35
 
9
36
  - [Gustavo Caso & Nikita Shilnikov] Added support for acronyms
10
37
 
11
- [Compare v0.1.1...master](https://github.com/dry-rb/dry-inflector/compare/v0.1.1...master)
12
38
 
13
- ## v0.1.1 - 2017-11-18
39
+ [Compare v0.1.1...v0.1.2](https://github.com/dry-rb/dry-inflector/compare/v0.1.1...v0.1.2)
40
+
41
+ ## 0.1.1 2017-11-18
42
+
43
+
14
44
  ### Fixed
45
+
15
46
  - [Luca Guidi & Abinoam P. Marques Jr.] Ensure `Dry::Inflector#ordinalize` to work for all the numbers from 0 to 100
16
47
 
48
+
17
49
  [Compare v0.1.0...v0.1.1](https://github.com/dry-rb/dry-inflector/compare/v0.1.0...v0.1.1)
18
50
 
19
- ## v0.1.0 - 2017-11-17
51
+ ## 0.1.0 2017-11-17
52
+
53
+
20
54
  ### Added
55
+
21
56
  - [Luca Guidi] Introduced `Dry::Inflector#pluralize`
22
57
  - [Luca Guidi] Introduced `Dry::Inflector#singularize`
23
58
  - [Luca Guidi] Introduced `Dry::Inflector#camelize`
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015-2021 dry-rb team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,109 +1,30 @@
1
- [gitter]: https://gitter.im/dry-rb/chat
2
- [gem]: https://img.shields.io/gem/v/dry-inflector.svg
3
- [travis]: https://travis-ci.org/dry-rb/dry-inflector
4
- [gemnasium]: https://gemnasium.com/dry-rb/dry-inflector
5
- [codeclimate]: https://codeclimate.com/github/dry-rb/dry-inflector
6
- [coveralls]: https://coveralls.io/r/dry-rb/dry-inflector
1
+ <!--- this file is synced from dry-rb/template-gem project -->
2
+ [gem]: https://rubygems.org/gems/dry-inflector
3
+ [actions]: https://github.com/dry-rb/dry-inflector/actions
4
+ [codacy]: https://www.codacy.com/gh/dry-rb/dry-inflector
5
+ [chat]: https://dry-rb.zulipchat.com
7
6
  [inchpages]: http://inch-ci.org/github/dry-rb/dry-inflector
8
7
 
9
- # dry-inflector [![Join the chat at https://gitter.im/dry-rb/chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/dry-rb/chat)
8
+ # dry-inflector [![Join the chat at https://dry-rb.zulipchat.com](https://img.shields.io/badge/dry--rb-join%20chat-%23346b7a.svg)][chat]
10
9
 
11
10
  [![Gem Version](https://badge.fury.io/rb/dry-inflector.svg)][gem]
12
- [![Build Status](https://travis-ci.org/dry-rb/dry-inflector.svg?branch=master)][travis]
13
- [![Dependency Status](https://gemnasium.com/dry-rb/dry-inflector.svg)][gemnasium]
14
- [![Code Climate](https://codeclimate.com/github/dry-rb/dry-inflector/badges/gpa.svg)][codeclimate]
15
- [![Test Coverage](https://codeclimate.com/github/dry-rb/dry-inflector/badges/coverage.svg)][codeclimate]
11
+ [![CI Status](https://github.com/dry-rb/dry-inflector/workflows/ci/badge.svg)][actions]
12
+ [![Codacy Badge](https://api.codacy.com/project/badge/Grade/00339f2fb77840149f999cac6110c8a8)][codacy]
13
+ [![Codacy Badge](https://api.codacy.com/project/badge/Coverage/00339f2fb77840149f999cac6110c8a8)][codacy]
16
14
  [![Inline docs](http://inch-ci.org/github/dry-rb/dry-inflector.svg?branch=master)][inchpages]
17
15
 
18
- dry-inflector is an inflector gem for Ruby.
16
+ ## Links
19
17
 
20
- ## Installation
18
+ * [User documentation](https://dry-rb.org/gems/dry-inflector)
19
+ * [API documentation](http://rubydoc.info/gems/dry-inflector)
21
20
 
22
- Add this line to your application's `Gemfile`:
21
+ ## Supported Ruby versions
23
22
 
24
- ```ruby
25
- gem 'dry-inflector'
26
- ```
23
+ This library officially supports the following Ruby versions:
27
24
 
28
- And then execute:
25
+ * MRI `>= 2.6.0`
26
+ * ~~jruby~~ `>= 9.3` (we are waiting for [2.6 support](https://github.com/jruby/jruby/issues/6161))
29
27
 
30
- ```shell
31
- $ bundle
32
- ```
28
+ ## License
33
29
 
34
- Or install it yourself as:
35
-
36
- ```shell
37
- $ gem install dry-inflector
38
- ```
39
-
40
- ## Usage
41
-
42
- ### Basic usage
43
-
44
- ```ruby
45
- require "dry/inflector"
46
-
47
- inflector = Dry::Inflector.new
48
-
49
- inflector.pluralize("book") # => "books"
50
- inflector.singularize("books") # => "book"
51
-
52
- inflector.camelize("dry/inflector") # => "Dry::Inflector"
53
- inflector.classify("books") # => "Book"
54
- inflector.tableize("Book") # => "books"
55
-
56
- inflector.dasherize("dry_inflector") # => "dry-inflector"
57
- inflector.underscore("dry-inflector") # => "dry_inflector"
58
-
59
- inflector.demodulize("Dry::Inflector") # => "Inflector"
60
-
61
- inflector.humanize("dry_inflector") # => "Dry inflector"
62
- inflector.humanize("author_id") # => "Author"
63
-
64
- inflector.ordinalize(1) # => "1st"
65
- inflector.ordinalize(2) # => "2nd"
66
- inflector.ordinalize(3) # => "3rd"
67
- inflector.ordinalize(10) # => "10th"
68
- inflector.ordinalize(23) # => "23rd"
69
- ```
70
-
71
- ### Custom inflection rules
72
-
73
- ```ruby
74
- require "dry/inflector"
75
-
76
- inflector = Dry::Inflector.new do |inflections|
77
- inflections.plural "virus", "viruses" # specify a rule for #pluralize
78
- inflections.singular "thieves", "thief" # specify a rule for #singularize
79
- inflections.uncountable "dry-inflector" # add an exception for an uncountable word
80
- end
81
-
82
- inflector.pluralize("virus") # => "viruses"
83
- inflector.singularize("thieves") # => "thief"
84
-
85
- inflector.pluralize("dry-inflector") # => "dry-inflector"
86
- ```
87
-
88
- ## Credits
89
-
90
- This gem is the cumulative effort of the Ruby community.
91
- It started with the extlib inflecto originated from [active_support](https://github.com/rails/rails), then dm-core inflector originated from [extlib](https://github.com/datamapper/extlib).
92
- Later, [`inflecto`](https://github.com/mbj/inflecto) was extracted from [dm-core](https://github.com/datamapper/dm-core) as a standalone inflector.
93
- Now, we resurrect `inflecto` and merged [`flexus`](https://github.com/Ptico/flexus), with some inflection rules from [`hanami-utils`](https://github.com/hanami/utils).
94
-
95
- This is `dry-inflector`.
96
-
97
- ## Development
98
-
99
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
100
-
101
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
102
-
103
- ## Contributing
104
-
105
- Bug reports and pull requests are welcome on GitHub at https://github.com/dry-rb/dry-inflector.
106
-
107
- ## Copyright
108
-
109
- Copyright © The Dry, Rails, Merb, Datamapper, Inflecto, Flexus, and Hanami teams - Released under the MIT License
30
+ See `LICENSE` file.
@@ -1,32 +1,36 @@
1
-
2
1
  # frozen_string_literal: true
3
2
 
4
- lib = File.expand_path("../lib", __FILE__)
3
+ # this file is synced from dry-rb/template-gem project
4
+
5
+ lib = File.expand_path("lib", __dir__)
5
6
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
7
  require "dry/inflector/version"
7
8
 
8
9
  Gem::Specification.new do |spec|
9
10
  spec.name = "dry-inflector"
10
- spec.version = Dry::Inflector::VERSION
11
11
  spec.authors = ["Luca Guidi", "Andrii Savchenko", "Abinoam P. Marques Jr."]
12
12
  spec.email = ["me@lucaguidi.com", "andrey@aejis.eu", "abinoam@gmail.com"]
13
-
14
- spec.summary = "DRY Inflector"
15
- spec.description = "String inflections for dry-rb"
16
- spec.homepage = "http://dry-rb.org"
17
13
  spec.license = "MIT"
14
+ spec.version = Dry::Inflector::VERSION.dup
15
+
16
+ spec.summary = "String inflections for dry-rb"
17
+ spec.description = spec.summary
18
+ spec.homepage = "https://dry-rb.org/gems/dry-inflector"
19
+ spec.files = Dir["CHANGELOG.md", "LICENSE", "README.md", "dry-inflector.gemspec", "lib/**/*"]
20
+ spec.bindir = "bin"
21
+ spec.executables = []
22
+ spec.require_paths = ["lib"]
18
23
 
19
24
  spec.metadata["allowed_push_host"] = "https://rubygems.org"
25
+ spec.metadata["changelog_uri"] = "https://github.com/dry-rb/dry-inflector/blob/master/CHANGELOG.md"
26
+ spec.metadata["source_code_uri"] = "https://github.com/dry-rb/dry-inflector"
27
+ spec.metadata["bug_tracker_uri"] = "https://github.com/dry-rb/dry-inflector/issues"
20
28
 
21
- spec.bindir = "exe"
22
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
- spec.require_paths = ["lib"]
29
+ spec.required_ruby_version = ">= 2.6.0"
24
30
 
25
- spec.files = `git ls-files -- lib/* CHANGELOG.md LICENSE.md README.md dry-inflector.gemspec`.split($INPUT_RECORD_SEPARATOR)
26
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
31
+ # to update dependencies edit project.yml
27
32
 
28
- spec.add_development_dependency "bundler", "~> 1.16"
29
- spec.add_development_dependency "rake", "~> 12.0"
30
- spec.add_development_dependency "rspec", "~> 3.7"
31
- spec.add_development_dependency "rubocop", "~> 0.50.0"
33
+ spec.add_development_dependency "bundler"
34
+ spec.add_development_dependency "rake"
35
+ spec.add_development_dependency "rspec"
32
36
  end
@@ -18,7 +18,7 @@ module Dry
18
18
 
19
19
  # @since 0.1.2
20
20
  # @api private
21
- def apply_to(word, capitalize = true)
21
+ def apply_to(word, capitalize: true)
22
22
  @rules[word.downcase] || (capitalize ? word.capitalize : word)
23
23
  end
24
24
 
@@ -9,7 +9,6 @@ module Dry
9
9
  # @api private
10
10
  #
11
11
  # rubocop:disable Metrics/AbcSize
12
- # rubocop:disable Metrics/MethodLength
13
12
  module Defaults
14
13
  # @since 0.1.0
15
14
  # @api private
@@ -35,7 +34,7 @@ module Dry
35
34
  inflect.plural(/(?<!b)um\z/i, '\1a')
36
35
  inflect.plural(/([ti])a\z/i, '\1a')
37
36
  inflect.plural(/sis\z/i, "ses")
38
- inflect.plural(/(.*)(?:([^f]))f[e]*\z/i, '\1\2ves')
37
+ inflect.plural(/(.*)(?:([^f]))fe*\z/i, '\1\2ves')
39
38
  inflect.plural(/(hive|proof)\z/i, '\1s') # TODO: proof can be moved in the above regexp
40
39
  inflect.plural(/([^aeiouy]|qu)y\z/i, '\1ies')
41
40
  inflect.plural(/(x|ch|ss|sh)\z/i, '\1es')
@@ -57,8 +56,9 @@ module Dry
57
56
  inflect.singular(/s\z/i, "")
58
57
  inflect.singular(/(n)ews\z/i, '\1ews')
59
58
  inflect.singular(/([ti])a\z/i, '\1um')
60
- inflect.singular(/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses\z/i, '\1\2sis')
61
- inflect.singular(/(^analy)ses\z/i, '\1sis')
59
+ inflect.singular(/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)(sis|ses)\z/i,
60
+ '\1\2sis')
61
+ inflect.singular(/(^analy)(sis|ses)\z/i, '\1sis')
62
62
  inflect.singular(/([^f])ves\z/i, '\1fe')
63
63
  inflect.singular(/(hive)s\z/i, '\1')
64
64
  inflect.singular(/(tive)s\z/i, '\1')
@@ -69,12 +69,12 @@ module Dry
69
69
  inflect.singular(/(ss)\z/i, '\1')
70
70
  inflect.singular(/(x|ch|ss|sh)es\z/i, '\1')
71
71
  inflect.singular(/([m|l])ice\z/i, '\1ouse')
72
- inflect.singular(/(bus)es\z/i, '\1')
72
+ inflect.singular(/(us)(es)?\z/i, '\1')
73
73
  inflect.singular(/(o)es\z/i, '\1')
74
74
  inflect.singular(/(shoe)s\z/i, '\1')
75
- inflect.singular(/(cris|ax|test)es\z/i, '\1is')
76
- inflect.singular(/(octop|vir)i\z/i, '\1us')
77
- inflect.singular(/(alias|status)es\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')
78
78
  inflect.singular(/^(ox)en/i, '\1')
79
79
  inflect.singular(/(vert|ind)ices\z/i, '\1ex')
80
80
  inflect.singular(/(matr)ices\z/i, '\1ix')
@@ -87,30 +87,34 @@ module Dry
87
87
  def self.irregular(inflect)
88
88
  inflect.irregular("person", "people")
89
89
  inflect.irregular("man", "men")
90
- inflect.irregular("human", "humans") # NOTE: this is here only to override the previous rule
90
+
91
+ # NOTE: this is here only to override the previous rule
92
+ inflect.irregular("human", "humans")
91
93
  inflect.irregular("child", "children")
92
94
  inflect.irregular("sex", "sexes")
93
95
  inflect.irregular("foot", "feet")
94
96
  inflect.irregular("tooth", "teeth")
95
97
  inflect.irregular("goose", "geese")
96
- inflect.irregular("forum", "forums") # FIXME: this is here because I need to fix the "um" regexp
98
+
99
+ # FIXME: this is here because I need to fix the "um" regexp
100
+ inflect.irregular("forum", "forums")
97
101
  end
98
102
 
99
103
  # @since 0.1.0
100
104
  # @api private
101
105
  def self.uncountable(inflect)
102
- inflect.uncountable(%w[hovercraft moose deer milk rain Swiss grass equipment information rice money species series fish sheep jeans])
106
+ inflect.uncountable(%w[hovercraft moose deer milk rain Swiss grass equipment information
107
+ rice money species series fish sheep jeans])
103
108
  end
104
109
 
105
110
  # @since 0.1.2
106
111
  # @api private
107
112
  def self.acronyms(inflect)
108
- inflect.acronym(*%w[JSON HTTP OpenSSL HMAC])
113
+ inflect.acronym(*%w[JSON HTTP OpenSSL HMAC CSRF API])
109
114
  end
110
115
 
111
116
  private_class_method :plural, :singular, :irregular, :uncountable, :acronyms
112
117
  end
113
- # rubocop:enable Metrics/MethodLength
114
118
  # rubocop:enable Metrics/AbcSize
115
119
  end
116
120
  end
@@ -87,7 +87,9 @@ module Dry
87
87
  #
88
88
  # Specifies a new pluralization rule and its replacement.
89
89
  # The rule can either be a string or a regular expression.
90
- # The replacement should always be a string that may include references to the matched data from the rule.
90
+ #
91
+ # The replacement should always be a string that may include
92
+ # references to the matched data from the rule.
91
93
  #
92
94
  # @param rule [String, Regexp] the rule
93
95
  # @param replacement [String] the replacement
@@ -108,7 +110,9 @@ module Dry
108
110
  #
109
111
  # Specifies a new singularization rule and its replacement.
110
112
  # The rule can either be a string or a regular expression.
111
- # The replacement should always be a string that may include references to the matched data from the rule.
113
+ #
114
+ # The replacement should always be a string that may include
115
+ # references to the matched data from the rule.
112
116
  #
113
117
  # @param rule [String, Regexp] the rule
114
118
  # @param replacement [String] the replacement
@@ -127,7 +131,9 @@ module Dry
127
131
 
128
132
  # Add a custom pluralization rule
129
133
  #
130
- # Specifies a new irregular that applies to both pluralization and singularization at the same time.
134
+ # Specifies a new irregular that applies to both pluralization
135
+ # and singularization at the same time.
136
+ #
131
137
  # This can only be used for strings, not regular expressions.
132
138
  # You simply pass the irregular in singular and plural form.
133
139
  #
@@ -194,9 +200,14 @@ module Dry
194
200
 
195
201
  # Add a custom humanize rule
196
202
  #
197
- # Specifies a humanized form of a string by a regular expression rule or by a string mapping.
198
- # When using a regular expression based replacement, the normal humanize formatting is called after the replacement.
199
- # When a string is used, the human form should be specified as desired (example: `"The name"`, not `"the_name"`)
203
+ # Specifies a humanized form of a string by a regular expression rule or
204
+ # by a string mapping.
205
+ #
206
+ # When using a regular expression based replacement, the normal humanize
207
+ # formatting is called after the replacement.
208
+ #
209
+ # When a string is used, the human form should be specified as desired
210
+ # (example: `"The name"`, not `"the_name"`)
200
211
  #
201
212
  # @param rule [String, Regexp] the rule
202
213
  # @param replacement [String] the replacement
@@ -227,7 +238,7 @@ module Dry
227
238
  # @api private
228
239
  def add_irregular(rule, replacement, target)
229
240
  head, *tail = rule.chars.to_a
230
- rule(/(#{head})#{tail.join}\z/i, '\1' + replacement[1..-1], target)
241
+ rule(/(#{head})#{tail.join}\z/i, "\\1#{replacement[1..]}", target)
231
242
  end
232
243
 
233
244
  # Add a new rule
@@ -3,6 +3,6 @@
3
3
  module Dry
4
4
  class Inflector
5
5
  # @since 0.1.0
6
- VERSION = "0.1.2"
6
+ VERSION = "0.2.1"
7
7
  end
8
8
  end
data/lib/dry/inflector.rb CHANGED
@@ -34,30 +34,41 @@ module Dry
34
34
  @inflections = Inflections.build(&blk)
35
35
  end
36
36
 
37
- # Camelize a string
37
+ # Lower camelize a string
38
38
  #
39
39
  # @param input [String,Symbol] the input
40
- # @return [String] the camelized string
40
+ # @return [String] the lower camelized string
41
41
  #
42
- # @since 0.1.0
42
+ # @since 0.1.3
43
43
  #
44
44
  # @example
45
45
  # require "dry/inflector"
46
46
  #
47
47
  # inflector = Dry::Inflector.new
48
- # inflector.camelize("dry/inflector") # => "Dry::Inflector"
49
- def camelize(input)
50
- input = input.to_s.dup
51
- input.sub!(/^[a-z\d]*/) { |match| inflections.acronyms.apply_to(match) }
52
- input.gsub!(%r{(?:_|(/))([a-z\d]*)}i) do
53
- m1 = Regexp.last_match(1)
54
- m2 = Regexp.last_match(2)
55
- "#{m1}#{inflections.acronyms.apply_to(m2)}"
56
- end
57
- input.gsub!("/", "::")
58
- input
48
+ # inflector.camelize_lower("data_mapper") # => "dataMapper"
49
+ def camelize_lower(input)
50
+ internal_camelize(input, false)
51
+ end
52
+
53
+ # Upper camelize a string
54
+ #
55
+ # @param input [String,Symbol] the input
56
+ # @return [String] the upper camelized string
57
+ #
58
+ # @since 0.1.3
59
+ #
60
+ # @example
61
+ # require "dry/inflector"
62
+ #
63
+ # inflector = Dry::Inflector.new
64
+ # inflector.camelize_upper("data_mapper") # => "DataMapper"
65
+ # inflector.camelize_upper("dry/inflector") # => "Dry::Inflector"
66
+ def camelize_upper(input)
67
+ internal_camelize(input, true)
59
68
  end
60
69
 
70
+ alias_method :camelize, :camelize_upper
71
+
61
72
  # Find a constant with the name specified in the argument string
62
73
  #
63
74
  # The name is assumed to be the one of a top-level constant,
@@ -75,7 +86,7 @@ module Dry
75
86
  # inflector.constantize("Module") # => Module
76
87
  # inflector.constantize("Dry::Inflector") # => Dry::Inflector
77
88
  def constantize(input)
78
- Object.const_get(input)
89
+ Object.const_get(input, false)
79
90
  end
80
91
 
81
92
  # Classify a string
@@ -147,7 +158,7 @@ module Dry
147
158
  match = /(?<separator>\W)/.match(result)
148
159
  separator = match ? match[:separator] : DEFAULT_SEPARATOR
149
160
  result.split(separator).map.with_index { |word, index|
150
- inflections.acronyms.apply_to(word, index.zero?)
161
+ inflections.acronyms.apply_to(word, capitalize: index.zero?)
151
162
  }.join(separator)
152
163
  end
153
164
 
@@ -181,7 +192,7 @@ module Dry
181
192
  # inflector.ordinalize(3) # => "3rd"
182
193
  # inflector.ordinalize(10) # => "10th"
183
194
  # inflector.ordinalize(23) # => "23rd"
184
- def ordinalize(number) # rubocop:disable Metrics/MethodLength
195
+ def ordinalize(number)
185
196
  abs_value = number.abs
186
197
 
187
198
  if ORDINALIZE_TH.key?(abs_value % 100)
@@ -212,6 +223,7 @@ module Dry
212
223
  def pluralize(input)
213
224
  input = input.to_s
214
225
  return input if uncountable?(input)
226
+
215
227
  inflections.plurals.apply_to(input)
216
228
  end
217
229
 
@@ -231,6 +243,7 @@ module Dry
231
243
  def singularize(input)
232
244
  input = input.to_s
233
245
  return input if uncountable?(input)
246
+
234
247
  inflections.singulars.apply_to(input)
235
248
  end
236
249
 
@@ -268,7 +281,7 @@ module Dry
268
281
  input.gsub!(inflections.acronyms.regex) do
269
282
  m1 = Regexp.last_match(1)
270
283
  m2 = Regexp.last_match(2)
271
- "#{m1 ? '_' : '' }#{m2.downcase}"
284
+ "#{m1 ? "_" : ""}#{m2.downcase}"
272
285
  end
273
286
  input.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
274
287
  input.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
@@ -288,6 +301,15 @@ module Dry
288
301
  !(input =~ /\A[[:space:]]*\z/).nil? || inflections.uncountables.include?(input.downcase)
289
302
  end
290
303
 
304
+ # @return [String]
305
+ #
306
+ # @since 0.2.0
307
+ # @api public
308
+ def to_s
309
+ "#<Dry::Inflector>"
310
+ end
311
+ alias_method :inspect, :to_s
312
+
291
313
  private
292
314
 
293
315
  # @since 0.1.0
@@ -298,8 +320,20 @@ module Dry
298
320
  # @api private
299
321
  DEFAULT_SEPARATOR = " "
300
322
 
301
- # @since 0.1.0
302
- # @api private
303
323
  attr_reader :inflections
324
+
325
+ # @since 0.1.3
326
+ # @api private
327
+ def internal_camelize(input, upper)
328
+ input = input.to_s.dup
329
+ input.sub!(/^[a-z\d]*/) { |match| inflections.acronyms.apply_to(match, capitalize: upper) }
330
+ input.gsub!(%r{(?:_|(/))([a-z\d]*)}i) do
331
+ m1 = Regexp.last_match(1)
332
+ m2 = Regexp.last_match(2)
333
+ "#{m1}#{inflections.acronyms.apply_to(m2)}"
334
+ end
335
+ input.gsub!("/", "::")
336
+ input
337
+ end
304
338
  end
305
339
  end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dry/inflector"
metadata CHANGED
@@ -1,73 +1,59 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-inflector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luca Guidi
8
8
  - Andrii Savchenko
9
9
  - Abinoam P. Marques Jr.
10
10
  autorequire:
11
- bindir: exe
11
+ bindir: bin
12
12
  cert_chain: []
13
- date: 2018-04-25 00:00:00.000000000 Z
13
+ date: 2021-06-30 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
- - - "~>"
19
+ - - ">="
20
20
  - !ruby/object:Gem::Version
21
- version: '1.16'
21
+ version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
- - - "~>"
26
+ - - ">="
27
27
  - !ruby/object:Gem::Version
28
- version: '1.16'
28
+ version: '0'
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: rake
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
- - - "~>"
33
+ - - ">="
34
34
  - !ruby/object:Gem::Version
35
- version: '12.0'
35
+ version: '0'
36
36
  type: :development
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
- - - "~>"
40
+ - - ">="
41
41
  - !ruby/object:Gem::Version
42
- version: '12.0'
42
+ version: '0'
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: rspec
45
45
  requirement: !ruby/object:Gem::Requirement
46
46
  requirements:
47
- - - "~>"
47
+ - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: '3.7'
49
+ version: '0'
50
50
  type: :development
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
- - - "~>"
54
+ - - ">="
55
55
  - !ruby/object:Gem::Version
56
- version: '3.7'
57
- - !ruby/object:Gem::Dependency
58
- name: rubocop
59
- requirement: !ruby/object:Gem::Requirement
60
- requirements:
61
- - - "~>"
62
- - !ruby/object:Gem::Version
63
- version: 0.50.0
64
- type: :development
65
- prerelease: false
66
- version_requirements: !ruby/object:Gem::Requirement
67
- requirements:
68
- - - "~>"
69
- - !ruby/object:Gem::Version
70
- version: 0.50.0
56
+ version: '0'
71
57
  description: String inflections for dry-rb
72
58
  email:
73
59
  - me@lucaguidi.com
@@ -78,20 +64,24 @@ extensions: []
78
64
  extra_rdoc_files: []
79
65
  files:
80
66
  - CHANGELOG.md
81
- - LICENSE.md
67
+ - LICENSE
82
68
  - README.md
83
69
  - dry-inflector.gemspec
70
+ - lib/dry-inflector.rb
84
71
  - lib/dry/inflector.rb
85
72
  - lib/dry/inflector/acronyms.rb
86
73
  - lib/dry/inflector/inflections.rb
87
74
  - lib/dry/inflector/inflections/defaults.rb
88
75
  - lib/dry/inflector/rules.rb
89
76
  - lib/dry/inflector/version.rb
90
- homepage: http://dry-rb.org
77
+ homepage: https://dry-rb.org/gems/dry-inflector
91
78
  licenses:
92
79
  - MIT
93
80
  metadata:
94
81
  allowed_push_host: https://rubygems.org
82
+ changelog_uri: https://github.com/dry-rb/dry-inflector/blob/master/CHANGELOG.md
83
+ source_code_uri: https://github.com/dry-rb/dry-inflector
84
+ bug_tracker_uri: https://github.com/dry-rb/dry-inflector/issues
95
85
  post_install_message:
96
86
  rdoc_options: []
97
87
  require_paths:
@@ -100,16 +90,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
100
90
  requirements:
101
91
  - - ">="
102
92
  - !ruby/object:Gem::Version
103
- version: '0'
93
+ version: 2.6.0
104
94
  required_rubygems_version: !ruby/object:Gem::Requirement
105
95
  requirements:
106
96
  - - ">="
107
97
  - !ruby/object:Gem::Version
108
98
  version: '0'
109
99
  requirements: []
110
- rubyforge_project:
111
- rubygems_version: 2.7.6
100
+ rubygems_version: 3.1.6
112
101
  signing_key:
113
102
  specification_version: 4
114
- summary: DRY Inflector
103
+ summary: String inflections for dry-rb
115
104
  test_files: []
data/LICENSE.md DELETED
@@ -1,22 +0,0 @@
1
- Copyright © The Dry, Rails, Merb, Datamapper, Inflecto, Flexus, and Hanami teams
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.