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

Already on GitHub? Sign in to your account

Experimental code. #97

Closed
wants to merge 6 commits into
from

Conversation

Projects
None yet
2 participants
Contributor

g1smd commented May 27, 2013

No description provided.

Contributor

g1smd commented May 27, 2013

match(..) ... processes numbers with specific length.

one_of(..) ... matches initial digits and doesn't care about the length.

How to constrain one_of(..) rules to work with specific number lengths?

Owner

floere commented May 27, 2013

How to constrain one_of(..) rules to work with specific number lengths?

That is not possible yet – there's only a max_length option, but I'd like to deprecate that one. We could add a only_length option, or similar.

Contributor

g1smd commented May 27, 2013

I see. While a number like 020 3000 9000 could potentially be allocated in London, 020 3000 90000 and 020 3000 900 are both never valid because they have too many or too few digits. Using match(..) and a suitable RegEx pattern testing the initial digits and the length, this can be catered for, but not when using one_of(..). I was looking for a simple way to fix that without going completely to RegEx patterns for all definitions.

While RegEx is often more efficient in matching, it becomes very difficult to maintain the patterns as, for the UK, they are very long. Another project I work with has RegEx to validate that a dialled number has the correct amount of digits based on the initial digits dialled and then separately formats numbers according to another pattern also based on inital digits. Both patterns work with initial digits rather than NDCs.

e.g. validates ^2(0[01378]|3[0189]|4[017]|8[0-46-9]|9[012])\d{7}$ as phone numbers that are possible,
but formats as ($1) $2 $3 using ^(2\d)(\d{4})(\d{4})$ to extract the digits - and then both types of RegEx pattern repeated many times for other number ranges.

I could get almost the same level of functionality here if I could specify a match if both "one_of" and "length" (or "match") were true.

Owner

floere commented May 27, 2013

I'm beginning to like your && which could also be used for simpler things like length(8) && one_of(...). What were the problems in your experimental code exploration?

Contributor

g1smd commented May 28, 2013

For commit 21182cc the errors are listed here: https://travis-ci.org/floere/phony/builds/7528738

I guess that part is supposed to return the NDC, but I expect it returns logical "TRUE" or garbage when the code with && is added.

I think part of the problem is that I don't understand the >> notation, and since I also don't know what that notation is called, two hours with the documentation also failed to find any mention of it.

Owner

floere commented Jun 2, 2013

I guess I should improve the documentation regarding >>. I call it the "then" operator, as in "match this number, then split it … | (or) match that other number, then …".

I am sadly a bit short on time at the moment, but happy to work on length(8) & one_of(…) or similar later this week.

Contributor

g1smd commented Jun 2, 2013

The split(..) function confused me to begin with. It seems that presenting the number +44 20 3000 4000 to country 44, one_of(20,23,24,28,29) >> split(4,4) has the split(..) function working with the remainder of the number after removing the +44 and the 20.

It would be good for the documentation to also describe what happens when that remainder has less than, or more than, 8 digits, exactly what the split(..) function does with that.

Owner

floere commented Jun 3, 2013

I hope I am not confusing you more by telling you that the functions, or methods actually don't do anything except build up a parser/splitter precedence array which is selected by the country digits, then worked through in order from top to bottom. If the part before the >> matches, then the part after the >> is used to split the right part into the right pieces.

And yes, you are absolutely right – the docs need to be better on that one. In fact, the whole README needs to be rewritten to be example based. Not brag-based, as I feel it is now.

Contributor

g1smd commented Jun 4, 2013

I now understand how it works. Seems simple enough.

Contributor

g1smd commented Jul 1, 2013

I'll have some time to return to this next week.

Owner

floere commented Apr 5, 2014

I can't remember anymore (understand from the discussion) what our goal here was. Any ideas? :)

@floere floere closed this Apr 27, 2014

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