dry-inflector 0.2.1 → 0.3.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: 6db17e7fbcdc21a6c06f9763e9267d78045ffa2772272cd93abfc22d54ae80a2
4
- data.tar.gz: bd47f925d3d558782192d3ce47cde9c9fb059163967a975e5d6298cd527e9912
3
+ metadata.gz: 74866c6fc9734bbf35266473131ad1b0cdf08a16a541f1b33d9c51d4787debe4
4
+ data.tar.gz: 18f73495b51877a6bfe2759df34f5a968f649b19200a7ed8981dc81eec3ea89f
5
5
  SHA512:
6
- metadata.gz: b97888420794db32aa69dbad0b168089a4be99d1c68f7411cefeabba1027e42d1f161147af435740e775ee6836dd5a48dad981c0f825b430c77c3e7eeade8091
7
- data.tar.gz: bf81663b753f1e370d4c8c8b84c844de54a7fce16613e8acbc8a0dcfc7302391f8a92edd51cdfb73fd163215aec9ff65db324d28b7df479a102b3f223ac64573
6
+ metadata.gz: e66e59ef5fa5b4ef6a12f108e20a9674e305ad808a850e4bde85b97f06b13b2f4b1c02763c3ccf0170afdcd30bb9b8c78f4413dfb0b40552971bf8b3ccf8d0e6
7
+ data.tar.gz: 8154dc57bbd78a19b35fe43bc611d94309d982583d2fdbe5265ef63e8e1ea698050e19790bf8124c959949ec3e4a070467c218a64d793f5c1e2dbd4db4751a3a
data/CHANGELOG.md CHANGED
@@ -1,25 +1,38 @@
1
1
  <!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
2
2
 
3
- ## unreleased
3
+ ## 0.3.0 2022-07-12
4
4
 
5
5
 
6
+ ### Added
7
+
8
+ - Add CSV as default acronym (via #43) (@waiting-for-dev)
9
+
10
+ ### Changed
11
+
12
+ - Extra dashes are now omitted when converting to camelcase (via #40) (@postmodern)
13
+
14
+ [Compare v0.2.1...v0.3.0](https://github.com/dry-rb/dry-inflector/compare/v0.2.1...v0.3.0)
15
+
16
+ ## 0.2.1 2021-06-30
17
+
18
+
19
+ ### Added
20
+
21
+ - Add default acronyms: API and CSRF (#35) (@jodosha)
22
+
6
23
  ### Fixed
7
24
 
8
25
  - Fix singularizing -us suffix (issue #33 via #38) (@cllns)
9
26
 
10
27
 
11
- [Compare v0.2.0...master](https://github.com/dry-rb/dry-inflector/compare/v0.2.0...master)
28
+ [Compare v0.2.0...v0.2.1](https://github.com/dry-rb/dry-inflector/compare/v0.2.0...v0.2.1)
12
29
 
13
30
  ## 0.2.0 2019-10-13
14
31
 
15
32
 
16
33
  ### Added
17
34
 
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
- - ```
35
+ - [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"' ```
23
36
 
24
37
  ### Fixed
25
38
 
data/README.md CHANGED
@@ -11,7 +11,7 @@
11
11
  [![CI Status](https://github.com/dry-rb/dry-inflector/workflows/ci/badge.svg)][actions]
12
12
  [![Codacy Badge](https://api.codacy.com/project/badge/Grade/00339f2fb77840149f999cac6110c8a8)][codacy]
13
13
  [![Codacy Badge](https://api.codacy.com/project/badge/Coverage/00339f2fb77840149f999cac6110c8a8)][codacy]
14
- [![Inline docs](http://inch-ci.org/github/dry-rb/dry-inflector.svg?branch=master)][inchpages]
14
+ [![Inline docs](http://inch-ci.org/github/dry-rb/dry-inflector.svg?branch=main)][inchpages]
15
15
 
16
16
  ## Links
17
17
 
@@ -22,8 +22,8 @@
22
22
 
23
23
  This library officially supports the following Ruby versions:
24
24
 
25
- * MRI `>= 2.6.0`
26
- * ~~jruby~~ `>= 9.3` (we are waiting for [2.6 support](https://github.com/jruby/jruby/issues/6161))
25
+ * MRI `>= 2.7.0`
26
+ * jruby `>= 9.3` (postponed until 2.7 is supported)
27
27
 
28
28
  ## License
29
29
 
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
26
26
  spec.metadata["source_code_uri"] = "https://github.com/dry-rb/dry-inflector"
27
27
  spec.metadata["bug_tracker_uri"] = "https://github.com/dry-rb/dry-inflector/issues"
28
28
 
29
- spec.required_ruby_version = ">= 2.6.0"
29
+ spec.required_ruby_version = ">= 2.7.0"
30
30
 
31
31
  # to update dependencies edit project.yml
32
32
 
@@ -110,7 +110,7 @@ module Dry
110
110
  # @since 0.1.2
111
111
  # @api private
112
112
  def self.acronyms(inflect)
113
- inflect.acronym(*%w[JSON HTTP OpenSSL HMAC CSRF API])
113
+ inflect.acronym(*%w[JSON HTTP OpenSSL HMAC CSRF API CSV])
114
114
  end
115
115
 
116
116
  private_class_method :plural, :singular, :irregular, :uncountable, :acronyms
@@ -3,6 +3,6 @@
3
3
  module Dry
4
4
  class Inflector
5
5
  # @since 0.1.0
6
- VERSION = "0.2.1"
6
+ VERSION = "0.3.0"
7
7
  end
8
8
  end
data/lib/dry/inflector.rb CHANGED
@@ -102,7 +102,7 @@ module Dry
102
102
  # inflector = Dry::Inflector.new
103
103
  # inflector.classify("books") # => "Book"
104
104
  def classify(input)
105
- camelize(singularize(input.to_s.sub(/.*\./, "")))
105
+ camelize(singularize(input.to_s.split(".").last))
106
106
  end
107
107
 
108
108
  # Dasherize a string
@@ -153,10 +153,10 @@ module Dry
153
153
  def humanize(input)
154
154
  input = input.to_s
155
155
  result = inflections.humans.apply_to(input)
156
- result.chomp!("_id")
156
+ result.delete_suffix!("_id")
157
157
  result.tr!("_", " ")
158
- match = /(?<separator>\W)/.match(result)
159
- separator = match ? match[:separator] : DEFAULT_SEPARATOR
158
+ match = /(\W)/.match(result)
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?)
162
162
  }.join(separator)
@@ -195,7 +195,7 @@ module Dry
195
195
  def ordinalize(number)
196
196
  abs_value = number.abs
197
197
 
198
- if ORDINALIZE_TH.key?(abs_value % 100)
198
+ if ORDINALIZE_TH[abs_value % 100]
199
199
  "#{number}th"
200
200
  else
201
201
  case abs_value % 10
@@ -260,7 +260,7 @@ module Dry
260
260
  # inflector = Dry::Inflector.new
261
261
  # inflector.tableize("Book") # => "books"
262
262
  def tableize(input)
263
- input = input.to_s.gsub(/::/, "_")
263
+ input = input.to_s.gsub("::", "_")
264
264
  pluralize(underscore(input))
265
265
  end
266
266
 
@@ -298,7 +298,7 @@ module Dry
298
298
  # @since 0.1.0
299
299
  # @api private
300
300
  def uncountable?(input)
301
- !(input =~ /\A[[:space:]]*\z/).nil? || inflections.uncountables.include?(input.downcase)
301
+ input.match?(/\A[[:space:]]*\z/) || inflections.uncountables.include?(input.downcase)
302
302
  end
303
303
 
304
304
  # @return [String]
@@ -314,7 +314,7 @@ module Dry
314
314
 
315
315
  # @since 0.1.0
316
316
  # @api private
317
- ORDINALIZE_TH = (11..13).each_with_object({}) { |n, ret| ret[n] = true }.freeze
317
+ ORDINALIZE_TH = {11 => true, 12 => true, 13 => true}.freeze
318
318
 
319
319
  # @since 0.1.2
320
320
  # @api private
@@ -327,7 +327,7 @@ module Dry
327
327
  def internal_camelize(input, upper)
328
328
  input = input.to_s.dup
329
329
  input.sub!(/^[a-z\d]*/) { |match| inflections.acronyms.apply_to(match, capitalize: upper) }
330
- input.gsub!(%r{(?:_|(/))([a-z\d]*)}i) do
330
+ input.gsub!(%r{(?:[_-]|(/))([a-z\d]*)}i) do
331
331
  m1 = Regexp.last_match(1)
332
332
  m2 = Regexp.last_match(2)
333
333
  "#{m1}#{inflections.acronyms.apply_to(m2)}"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-inflector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luca Guidi
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2021-06-30 00:00:00.000000000 Z
13
+ date: 2022-07-12 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -90,7 +90,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
90
90
  requirements:
91
91
  - - ">="
92
92
  - !ruby/object:Gem::Version
93
- version: 2.6.0
93
+ version: 2.7.0
94
94
  required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  requirements:
96
96
  - - ">="