Difference between revisions of "Module:Range/doc"
Jump to navigation
Jump to search
blackwiki>קיפודנחש |
blackwiki>קיפודנחש (whitespance) |
||
| Line 2: | Line 2: | ||
Returns one function called "iswitch", which takes its inspiration from <nowiki>{{#switch</nowiki>, but is limited to numeric values, and allows for ranges. | Returns one function called "iswitch", which takes its inspiration from <nowiki>{{#switch</nowiki>, but is limited to numeric values, and allows for ranges. | ||
| − | usage: | + | usage: |
<nowiki>{{#invoke:Range | iswitch | <nowiki>{{#invoke:Range | iswitch | ||
| Line 8: | Line 8: | ||
| 1 2 3..7 50..70 = one, two, three to seven, or fifty to seventy | | 1 2 3..7 50..70 = one, two, three to seven, or fifty to seventy | ||
| 9..40 = between nine and forty (inclusive) | | 9..40 = between nine and forty (inclusive) | ||
| − | | [41..48] = between 41 and 48 (inclusive) | + | | [41..48] = between 41 and 48 (inclusive) |
| (80..100 = larger (but not equal) than 80, and less or equal than 100 | | (80..100 = larger (but not equal) than 80, and less or equal than 100 | ||
| − | | (120..140) = larger (but not equal) than 120 and smaller than 140 | + | | (120..140) = larger (but not equal) than 120 and smaller than 140 |
| − | | ..-2e9) = any number smaller (but not equal) than minus two billion | + | | ..-2e9) = any number smaller (but not equal) than minus two billion |
| -2e9..0.75 = between minus two billion and three quuarters | | -2e9..0.75 = between minus two billion and three quuarters | ||
| 1e6.. = equal or larger than 1 million | | 1e6.. = equal or larger than 1 million | ||
| − | | default = None of the ranges matches the value | + | | default = None of the ranges matches the value |
}}</nowiki> | }}</nowiki> | ||
| Line 26: | Line 26: | ||
:When a range begins with (, it means the value has to be larger than the left limit. otherwise, it can be equal to the left limit. For convenience, [ can be used to mark "larger or equal", but it's not required (i.e. "1..100" is the same as "[1..100" | :When a range begins with (, it means the value has to be larger than the left limit. otherwise, it can be equal to the left limit. For convenience, [ can be used to mark "larger or equal", but it's not required (i.e. "1..100" is the same as "[1..100" | ||
| − | : Similarly, when a range ends with ) it means the value has to be strictly less than the right limit. | + | : Similarly, when a range ends with ) it means the value has to be strictly less than the right limit. |
:A range may begin or end with ".." | :A range may begin or end with ".." | ||
| − | :Such that ..100 means "100 or smaller", and 60.. means "60 or larger". | + | :Such that ..100 means "100 or smaller", and 60.. means "60 or larger". |
| − | :"..100)" means smaller than 100, and "(60.." means larger than 60 | + | :"..100)" means smaller than 100, and "(60.." means larger than 60 |
if '''value''' matches a ranges, the function will return the "Result" of one of the matching ranges. If more than one range matches, it is unpredictable which of the results will be returned. The function does not test for overlap. | if '''value''' matches a ranges, the function will return the "Result" of one of the matching ranges. If more than one range matches, it is unpredictable which of the results will be returned. The function does not test for overlap. | ||
Revision as of 01:42, 19 March 2013
| 40px | This is a documentation subpage for Module:Range. It contains usage information, categories and other content that is not part of the original module page. |
Returns one function called "iswitch", which takes its inspiration from {{#switch, but is limited to numeric values, and allows for ranges.
usage:
{{#invoke:Range | iswitch
| value = 12
| 1 2 3..7 50..70 = one, two, three to seven, or fifty to seventy
| 9..40 = between nine and forty (inclusive)
| [41..48] = between 41 and 48 (inclusive)
| (80..100 = larger (but not equal) than 80, and less or equal than 100
| (120..140) = larger (but not equal) than 120 and smaller than 140
| ..-2e9) = any number smaller (but not equal) than minus two billion
| -2e9..0.75 = between minus two billion and three quuarters
| 1e6.. = equal or larger than 1 million
| default = None of the ranges matches the value
}}
syntax: {{#invoke:Range | iswitch | value = <Number> | ( <Ranges> = Result | )... [default=Result] }}
- <Number> ::= [-][digits][.][digits][e digits]
- <Ranges> ::= [ <Number> | <Range> ]...
- <Range> ::= [ [ [ | ( ] [<Number>] .. [<Number>] [ ] | ) ]
- Result ::= any string (can be multiline) that does not contain | or }} (if needed, use Template:T, and Template:T. )
- When a range begins with (, it means the value has to be larger than the left limit. otherwise, it can be equal to the left limit. For convenience, [ can be used to mark "larger or equal", but it's not required (i.e. "1..100" is the same as "[1..100"
- Similarly, when a range ends with ) it means the value has to be strictly less than the right limit.
- A range may begin or end with ".."
- Such that ..100 means "100 or smaller", and 60.. means "60 or larger".
- "..100)" means smaller than 100, and "(60.." means larger than 60
if value matches a ranges, the function will return the "Result" of one of the matching ranges. If more than one range matches, it is unpredictable which of the results will be returned. The function does not test for overlap.
if none of the ranges match, and there is a "default", this value will return. otherwise, the function will return an empty string.
For tests see Module talk:Range/tests