Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit not recognized error after 4.0.0 upgrade #330

Closed
smathieu opened this issue Oct 31, 2023 · 3 comments · Fixed by #331
Closed

Unit not recognized error after 4.0.0 upgrade #330

smathieu opened this issue Oct 31, 2023 · 3 comments · Fixed by #331
Assignees
Labels
bug confirmed Patch backwards-compatible bug fixes

Comments

@smathieu
Copy link

We had some definitions that worked with the 3.0.0 release that are now failing after the upgrade.

Here's a short script to reproduce the issue:

require "ruby-units"

Unit.define("m2") do |u|
  u.definition = Unit.new("1 m") * Unit.new("1 m")
  u.display_name = "m^2"
  u.aliases = ["m²", "square_meter"]
end

puts Unit.new("1 m2") # => 1 m^2
puts Unit.new("1 square_meter") # => raise(ArgumentError, "'#{passed_unit_string}' Unit not recognized") unless used.empty?

This works in the 3.0.0 release, but raises an exception in the latest release. This does not seem to be an intended change.

@olbrich
Copy link
Owner

olbrich commented Oct 31, 2023

I think the problem here is the _ in the alias name. The parsing algorithm strips those out so that numbers can be passed in like 1_000_000, but it also impacts the unit name. I'll look into making that a little more specific so that it only strips out underscores in numbers, but you might be able to use a - instead in the meantime.

See

unit_string.gsub!(/[%'"#_,]/, '%' => 'percent', "'" => 'feet', '"' => 'inch', '#' => 'pound', '_' => '', ',' => '')

@olbrich olbrich added bug confirmed Patch backwards-compatible bug fixes labels Oct 31, 2023
@smathieu
Copy link
Author

Thanks for the quick response! This isn't super urgent, but is preventing us from updating. The square_meter strings comes from an external API, so we can't control this.

@olbrich
Copy link
Owner

olbrich commented Nov 1, 2023

@smathieu can you please verify if the branch associated with #331 fixes your issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug confirmed Patch backwards-compatible bug fixes
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants