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

Make adding units with SI prefixes simpler #88

Closed
thegedge opened this issue Apr 5, 2017 · 3 comments · Fixed by #90
Closed

Make adding units with SI prefixes simpler #88

thegedge opened this issue Apr 5, 2017 · 3 comments · Fixed by #90

Comments

@thegedge
Copy link
Contributor

thegedge commented Apr 5, 2017

I'm thinking we could add an SI helper when building a unit system, which will generate units with the SI prefixes added. Something along the lines:

si_unit :g, aliases: [:gram, :grams]
unit :g, aliases: [:gram, :grams], with_si_prefixes: true

This would generate kilograms, megagrams, micrograms, etc.

@kirinrastogi
Copy link
Contributor

kirinrastogi commented Apr 6, 2017

What range would this go to by default? 109 to 10-9 or even more?

@kirinrastogi
Copy link
Contributor

kirinrastogi commented Apr 6, 2017

I have started on this, and I don't know if the approach I am taking is good.

I was going to create a class Measured::SIUnitSystemBuilder
with def si_unit(unit_name, aliases: [], value: nil, range = 9)
The class would have two arrays, each with every 3 prefixes, and they can be as long as needed
[:k, :M, :G], and [:m, :μ, :n] would be snippets of them

Then something would iterate over these and call build_unit them, with default aliases "#{unit_name}s"
And set the value of the unit relative to the si base unit.

Am I on the right track here?
Also, I wasn't sure why with_si_prefixes: true is needed. Can't si_unit build the base unit, as well as ones with all of the prefixes?

@thegedge
Copy link
Contributor Author

thegedge commented Apr 6, 2017

From browsing around the web it looks like there are 20 prefixes (see Wikipedia, for example), so I'd go with those.

I'll address your other questions in your (wip) PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants