Skip to content

Commit

Permalink
Attempt to address unexpected inflections (#47)
Browse files Browse the repository at this point in the history
* Update singularize_spec to demonstrate bug

* Address analyses results

* Not sure why we need this ^

* support uncountables with word boundaries
  • Loading branch information
parndt authored May 8, 2023
1 parent 657085c commit b9707db
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/dry/inflector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,9 @@ def underscore(input)
# @since 0.1.0
# @api private
def uncountable?(input)
input.match?(/\A[[:space:]]*\z/) || inflections.uncountables.include?(input.downcase)
input.match?(/\A[[:space:]]*\z/) ||
inflections.uncountables.include?(input.downcase) ||
inflections.uncountables.include?(input.split(/_|\b/).last.downcase)
end

# @return [String]
Expand Down
4 changes: 2 additions & 2 deletions lib/dry/inflector/inflections/defaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def self.singular(inflect)
inflect.singular(/s\z/i, "")
inflect.singular(/(n)ews\z/i, '\1ews')
inflect.singular(/([ti])a\z/i, '\1um')
inflect.singular(/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)(sis|ses)\z/i,
inflect.singular(/(analy|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)(sis|ses)\z/i,
'\1\2sis')
inflect.singular(/(^analy)(sis|ses)\z/i, '\1sis')
inflect.singular(/([^f])ves\z/i, '\1fe')
Expand All @@ -75,7 +75,7 @@ def self.singular(inflect)
inflect.singular(/(cris|ax|test)(is|es)\z/i, '\1is')
inflect.singular(/(octop|vir)(us|i)\z/i, '\1us')
inflect.singular(/(alias|status)(es)?\z/i, '\1')
inflect.singular(/^(ox)en/i, '\1')
inflect.singular(/(ox)en/i, '\1')
inflect.singular(/(vert|ind)ices\z/i, '\1ex')
inflect.singular(/(matr)ices\z/i, '\1ix')
inflect.singular(/(quiz)zes\z/i, '\1')
Expand Down
12 changes: 12 additions & 0 deletions spec/unit/dry/inflector/singularize_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@
it "singularizes #{plural} => #{singular}" do
expect(subject.singularize(i(plural))).to eq(singular)
end

it "singularizes test_#{plural} => test_#{singular}" do
expect(subject.singularize(i("test_#{plural}"))).to eq("test_#{singular}")
end

it "singularizes test-#{plural} => test-#{singular}" do
expect(subject.singularize(i("test-#{plural}"))).to eq("test-#{singular}")
end

it "singularizes 'test #{plural}' => 'test #{singular}'" do
expect(subject.singularize(i("test #{plural}"))).to eq("test #{singular}")
end
end

Fixtures::Singularize.pending.each do |plural, singular|
Expand Down

0 comments on commit b9707db

Please sign in to comment.