Skip to content

allowing strings without space between scalar & unit#36

Closed
avitevet wants to merge 1 commit intoolbrich:masterfrom
avitevet:master
Closed

allowing strings without space between scalar & unit#36
avitevet wants to merge 1 commit intoolbrich:masterfrom
avitevet:master

Conversation

@avitevet
Copy link

Hi,

I've recently discovered your ruby-units gem and would like to use it in my project (fitlogr.com). The functionality will be perfect for allowing user input in many types of distance or weight.

I will need it to allow numbers & units without space in between them, like "5k" or "95lbs." With the code currently in the github repo, when I run "1.1m".to_unit in irb, I get a systemstackerror, "stack level too deep." So I made a change that stops this from happening. I also cleaned up the test/ directory & added a test to the test_ruby-units.rb file, only because I'm familiar with that environment and not with the rspec environment.

I would like this change merged back into your repo because I think that this is the only change I'll make to the gem, and I would like to continue to get your updates without first merging them into my fork.

Thanks,

Avi

Fixes test/ files
* tests code in working dir rather than installed dir
* removes or updates failing tests
@olbrich
Copy link
Owner

olbrich commented Feb 26, 2012

The problem with this sort of change is that it introduces ambiguity into the parsing of units. For example, '11/m' could be interpreted as '1 1/m' or '11 1/m'.

However, there does seem to be some need/desire for this feature as this is the second pull request for essentially the same thing. I'll revisit this feature in the near future. Perhaps this can be a configuration option for now.

@avitevet
Copy link
Author

You are right, I will also think more about this.

Does the ambiguity occur only for units with negative exponents? I've only worked with a very limited subset of your software for about 3 days so I don't understand all the various types of units it can handle. It seems to me that a string like "111/m" can only be validly interpreted as "11 1/m." It seems like "111 /m" is invalid as is "1 11/m" and "111/m (one hundred eleven over m)." Also, it seems to me that a string like "322/m" is not valid at all. Can you please comment on that?

Thanks,

Avi

@olbrich
Copy link
Owner

olbrich commented Feb 27, 2012

technically, something like "322/m" should be equivalent to "322 1/m". I think the only ambiguous case that might actually happen in practice would be something like "11/m". At this point, I'm inclined to interpret this as "1 1/m" instead of "11/m".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants