nrser 0.3.9 → 0.3.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/nrser/char/alpha_numeric_sub.rb +9 -19
- data/lib/nrser/char/special.rb +5 -5
- data/lib/nrser/core_ext/array.rb +36 -13
- data/lib/nrser/core_ext/enumerable.rb +1 -0
- data/lib/nrser/core_ext/enumerable/find_map.rb +1 -1
- data/lib/nrser/core_ext/hash/bury.rb +3 -0
- data/lib/nrser/core_ext/hash/extract_values_at.rb +2 -2
- data/lib/nrser/core_ext/method/full_name.rb +1 -1
- data/lib/nrser/core_ext/module/method_objects.rb +1 -1
- data/lib/nrser/core_ext/module/source_locations.rb +27 -15
- data/lib/nrser/core_ext/object/lazy_var.rb +1 -1
- data/lib/nrser/core_ext/pathname.rb +67 -12
- data/lib/nrser/core_ext/pathname/subpath.rb +86 -0
- data/lib/nrser/core_ext/string.rb +28 -1
- data/lib/nrser/core_ext/symbol.rb +11 -12
- data/lib/nrser/errors/README.md +154 -0
- data/lib/nrser/errors/attr_error.rb +146 -53
- data/lib/nrser/errors/count_error.rb +61 -12
- data/lib/nrser/errors/nicer_error.rb +42 -71
- data/lib/nrser/errors/value_error.rb +53 -58
- data/lib/nrser/functions.rb +0 -2
- data/lib/nrser/functions/enumerable.rb +5 -17
- data/lib/nrser/functions/enumerable/associate.rb +14 -5
- data/lib/nrser/functions/enumerable/find_all_map.rb +1 -1
- data/lib/nrser/functions/enumerable/include_slice/array_include_slice.rb +1 -1
- data/lib/nrser/functions/hash/bury.rb +2 -12
- data/lib/nrser/functions/merge_by.rb +2 -2
- data/lib/nrser/functions/module/method_objects.rb +2 -2
- data/lib/nrser/functions/path.rb +185 -165
- data/lib/nrser/functions/path/normalized.rb +84 -0
- data/lib/nrser/functions/string.rb +4 -4
- data/lib/nrser/functions/text/README.md +4 -0
- data/lib/nrser/functions/text/format.rb +53 -0
- data/lib/nrser/functions/text/indentation.rb +6 -6
- data/lib/nrser/functions/text/word_wrap.rb +2 -2
- data/lib/nrser/functions/tree/map_leaves.rb +3 -3
- data/lib/nrser/functions/tree/map_tree.rb +2 -2
- data/lib/nrser/functions/tree/transform.rb +1 -18
- data/lib/nrser/gem_ext/README.md +4 -0
- data/lib/nrser/labs/README.md +8 -0
- data/lib/nrser/labs/config.rb +163 -0
- data/lib/nrser/labs/i8.rb +49 -159
- data/lib/nrser/labs/i8/struct.rb +167 -0
- data/lib/nrser/labs/i8/struct/hash.rb +140 -0
- data/lib/nrser/labs/i8/struct/vector.rb +149 -0
- data/lib/nrser/labs/i8/surjection.rb +211 -0
- data/lib/nrser/labs/lots/consumer.rb +19 -0
- data/lib/nrser/labs/lots/parser.rb +21 -1
- data/lib/nrser/labs/stash.rb +4 -4
- data/lib/nrser/log.rb +25 -21
- data/lib/nrser/log/appender/sync.rb +15 -11
- data/lib/nrser/log/formatters/color.rb +0 -3
- data/lib/nrser/log/formatters/mixin.rb +4 -4
- data/lib/nrser/log/logger.rb +54 -6
- data/lib/nrser/log/mixin.rb +2 -1
- data/lib/nrser/log/plugin.rb +6 -6
- data/lib/nrser/log/types.rb +46 -29
- data/lib/nrser/mean_streak.rb +0 -8
- data/lib/nrser/mean_streak/document.rb +1 -4
- data/lib/nrser/message.rb +3 -3
- data/lib/nrser/meta/README.md +4 -0
- data/lib/nrser/meta/lazy_attr.rb +2 -2
- data/lib/nrser/meta/source/location.rb +1 -1
- data/lib/nrser/props.rb +34 -3
- data/lib/nrser/props/class_methods.rb +2 -1
- data/lib/nrser/props/instance_methods.rb +9 -9
- data/lib/nrser/props/metadata.rb +4 -12
- data/lib/nrser/props/mutable/stash.rb +5 -2
- data/lib/nrser/props/prop.rb +10 -19
- data/lib/nrser/rspex.rb +1 -20
- data/lib/nrser/rspex/example_group/describe_attribute.rb +3 -0
- data/lib/nrser/rspex/example_group/describe_called_with.rb +9 -4
- data/lib/nrser/rspex/example_group/describe_case.rb +1 -0
- data/lib/nrser/rspex/example_group/describe_class.rb +2 -0
- data/lib/nrser/rspex/example_group/describe_group.rb +1 -1
- data/lib/nrser/rspex/example_group/describe_instance.rb +3 -1
- data/lib/nrser/rspex/example_group/describe_message.rb +1 -1
- data/lib/nrser/rspex/example_group/describe_method.rb +64 -30
- data/lib/nrser/rspex/example_group/describe_response_to.rb +1 -1
- data/lib/nrser/rspex/example_group/describe_section.rb +4 -1
- data/lib/nrser/rspex/example_group/describe_sent_to.rb +1 -1
- data/lib/nrser/rspex/example_group/describe_setup.rb +1 -0
- data/lib/nrser/rspex/example_group/describe_source_file.rb +1 -1
- data/lib/nrser/rspex/example_group/describe_spec_file.rb +4 -2
- data/lib/nrser/rspex/example_group/describe_when.rb +2 -1
- data/lib/nrser/rspex/example_group/describe_x.rb +5 -5
- data/lib/nrser/rspex/format.rb +0 -15
- data/lib/nrser/sugar/method_missing_forwarder.rb +3 -3
- data/lib/nrser/sys/env/path.rb +2 -28
- data/lib/nrser/types.rb +63 -12
- data/lib/nrser/types/README.md +76 -0
- data/lib/nrser/types/arrays.rb +192 -137
- data/lib/nrser/types/attributes.rb +269 -0
- data/lib/nrser/types/booleans.rb +134 -83
- data/lib/nrser/types/bounded.rb +110 -47
- data/lib/nrser/types/collections.rb +119 -0
- data/lib/nrser/types/combinators.rb +283 -196
- data/lib/nrser/types/doc/display_table.md +66 -0
- data/lib/nrser/types/eqiuvalent.rb +91 -0
- data/lib/nrser/types/errors/check_error.rb +5 -11
- data/lib/nrser/types/errors/from_string_error.rb +3 -3
- data/lib/nrser/types/factory.rb +287 -20
- data/lib/nrser/types/hashes.rb +227 -179
- data/lib/nrser/types/in.rb +73 -36
- data/lib/nrser/types/is.rb +67 -60
- data/lib/nrser/types/is_a.rb +141 -84
- data/lib/nrser/types/labels.rb +45 -16
- data/lib/nrser/types/maybe.rb +6 -3
- data/lib/nrser/types/nil.rb +64 -27
- data/lib/nrser/types/not.rb +92 -34
- data/lib/nrser/types/numbers.rb +224 -169
- data/lib/nrser/types/pairs.rb +113 -89
- data/lib/nrser/types/paths.rb +250 -137
- data/lib/nrser/types/responds.rb +167 -89
- data/lib/nrser/types/selector.rb +234 -0
- data/lib/nrser/types/shape.rb +136 -65
- data/lib/nrser/types/strings.rb +189 -63
- data/lib/nrser/types/symbols.rb +83 -33
- data/lib/nrser/types/top.rb +89 -0
- data/lib/nrser/types/tuples.rb +134 -98
- data/lib/nrser/types/type.rb +617 -505
- data/lib/nrser/types/when.rb +123 -98
- data/lib/nrser/types/where.rb +182 -91
- data/lib/nrser/version.rb +1 -1
- data/spec/lib/nrser/core_ext/pathname/subpath_spec.rb +22 -0
- data/spec/lib/nrser/errors/attr_error_spec.rb +68 -0
- data/spec/lib/nrser/errors/count_error_spec.rb +69 -0
- data/spec/lib/nrser/functions/path/normalize_path_spec.rb +35 -0
- data/spec/lib/nrser/functions/tree/map_tree_spec.rb +74 -96
- data/spec/lib/nrser/functions/tree/transform_spec.rb +11 -11
- data/spec/lib/nrser/labs/config_spec.rb +22 -0
- data/spec/lib/nrser/labs/i8/struct_spec.rb +39 -0
- data/spec/lib/nrser/types/display_spec.rb +50 -0
- data/spec/lib/nrser/types/paths_spec.rb +16 -10
- data/spec/lib/nrser/types/selector_spec.rb +125 -0
- data/spec/spec_helper.rb +4 -5
- metadata +105 -22
- data/lib/nrser/types/any.rb +0 -41
- data/lib/nrser/types/attrs.rb +0 -213
- data/lib/nrser/types/trees.rb +0 -42
data/lib/nrser/types/maybe.rb
CHANGED
@@ -67,17 +67,20 @@ end # class Maybe
|
|
67
67
|
# @!group Type Factory Functions
|
68
68
|
# ----------------------------------------------------------------------------
|
69
69
|
|
70
|
-
# @!method
|
70
|
+
# @!method self.Maybe type, **options
|
71
71
|
# Type satisfied by `nil` or the parametrized type.
|
72
72
|
#
|
73
73
|
# @param [Type] type
|
74
74
|
# The type values must be if they are not `nil`.
|
75
75
|
#
|
76
|
-
# @param
|
76
|
+
# @param [Hash] options (see Type.initialize)
|
77
77
|
#
|
78
78
|
# @return [Type]
|
79
79
|
#
|
80
|
-
|
80
|
+
def_type :Maybe,
|
81
|
+
parameterize: :type,
|
82
|
+
default_name: false,
|
83
|
+
&->( type, **options ) do
|
81
84
|
Maybe.new type, **options
|
82
85
|
end
|
83
86
|
|
data/lib/nrser/types/nil.rb
CHANGED
@@ -1,28 +1,65 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# Requirements
|
5
|
+
# ========================================================================
|
6
|
+
|
7
|
+
# Project / Package
|
8
|
+
# ------------------------------------------------------------------------
|
9
|
+
|
1
10
|
require_relative './is'
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
11
|
+
|
12
|
+
|
13
|
+
# Namespace
|
14
|
+
# ========================================================================
|
15
|
+
|
16
|
+
module NRSER
|
17
|
+
module Types
|
18
|
+
|
19
|
+
|
20
|
+
# Definitions
|
21
|
+
# ========================================================================
|
22
|
+
|
23
|
+
# @!group Nil Type Factories
|
24
|
+
# ----------------------------------------------------------------------------
|
25
|
+
|
26
|
+
#@!method self.Nil **options
|
27
|
+
# Type for `nil`; itself and only.
|
28
|
+
#
|
29
|
+
# @todo
|
30
|
+
# Should we have a `#from_s` that converts the empty string to `nil`?
|
31
|
+
#
|
32
|
+
# Kind-of seems like we would want that to be a different types so that
|
33
|
+
# you can have a Nil type that is distinct from the empty string in
|
34
|
+
# parsing, but also have a type that accepts the empty string and coverts
|
35
|
+
# it to `nil`?
|
36
|
+
#
|
37
|
+
# Something like:
|
38
|
+
#
|
39
|
+
# type = t.empty | t.non_empty_str
|
40
|
+
# type.from_s ''
|
41
|
+
# # => nil
|
42
|
+
# type.from_s 'blah'
|
43
|
+
# # => 'blah'
|
44
|
+
#
|
45
|
+
# @param [Hash] options
|
46
|
+
# Passed to {Type#initialize}.
|
47
|
+
#
|
48
|
+
# @return [Type]
|
49
|
+
#
|
50
|
+
def_type :Nil,
|
51
|
+
aliases: [ :null ],
|
52
|
+
# `.Nil?` would not make any sense...
|
53
|
+
maybe: false,
|
54
|
+
&->( **options ) do
|
55
|
+
is nil, **options
|
56
|
+
end # .Nil
|
57
|
+
|
58
|
+
# @!endgroup Nil Type Factories # ********************************************
|
59
|
+
|
60
|
+
|
61
|
+
# /Namespace
|
62
|
+
# ========================================================================
|
63
|
+
|
64
|
+
end # module Types
|
65
|
+
end # module NRSER
|
data/lib/nrser/types/not.rb
CHANGED
@@ -1,43 +1,101 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
+
# Requirements
|
5
|
+
# ========================================================================
|
6
|
+
|
7
|
+
# Project / Package
|
8
|
+
# ------------------------------------------------------------------------
|
9
|
+
|
10
|
+
require_relative './type'
|
11
|
+
|
12
|
+
|
13
|
+
# Namespace
|
14
|
+
# ========================================================================
|
15
|
+
|
16
|
+
module NRSER
|
17
|
+
module Types
|
18
|
+
|
4
19
|
|
5
20
|
# Definitions
|
6
21
|
# =======================================================================
|
7
22
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
:not,
|
39
|
-
) do |type, **options|
|
40
|
-
Not.new type, **options
|
23
|
+
# Negation {Type} - A {Type} that parameterizes another {#type} by admitting
|
24
|
+
# values that the {#type} does not.
|
25
|
+
#
|
26
|
+
# @note
|
27
|
+
# Construct {Not} types using the {.Not} factory.
|
28
|
+
#
|
29
|
+
class Not < Type
|
30
|
+
|
31
|
+
# The type this one isn't.
|
32
|
+
#
|
33
|
+
# @return [Type]
|
34
|
+
#
|
35
|
+
attr_reader :type
|
36
|
+
|
37
|
+
|
38
|
+
# Constructor
|
39
|
+
# ======================================================================
|
40
|
+
|
41
|
+
# Instantiate a new `NRSER::Types::Not`.
|
42
|
+
def initialize type, **options
|
43
|
+
super **options
|
44
|
+
@type = NRSER::Types.make type
|
45
|
+
end # #initialize
|
46
|
+
|
47
|
+
|
48
|
+
# Instance Methods
|
49
|
+
# ======================================================================
|
50
|
+
|
51
|
+
def test? value
|
52
|
+
! type.test( value )
|
41
53
|
end
|
42
54
|
|
43
|
-
|
55
|
+
|
56
|
+
def default_symbolic
|
57
|
+
"#{ NRSER::Types.Top.symbolic }#{ COMPLEMENT }#{ type.symbolic }"
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
def default_name
|
62
|
+
"#{ NOT }#{ type.name }"
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
def explain
|
67
|
+
"#{ self.class.demod_name }<#{ type.explain }>"
|
68
|
+
end
|
69
|
+
|
70
|
+
end # class Not
|
71
|
+
|
72
|
+
|
73
|
+
# @!group Negation Type Factories
|
74
|
+
# ----------------------------------------------------------------------------
|
75
|
+
|
76
|
+
#@!method self.Not type, **options
|
77
|
+
# Negates another type.
|
78
|
+
#
|
79
|
+
# @param [TYPE] type
|
80
|
+
# The type to negate, made into one via {.make} if it's not already.
|
81
|
+
#
|
82
|
+
# @param [Hash] options
|
83
|
+
# Passed to {Type#initialize}.
|
84
|
+
#
|
85
|
+
# @return [Not]
|
86
|
+
#
|
87
|
+
def_type :Not,
|
88
|
+
default_name: false,
|
89
|
+
parameterize: :type,
|
90
|
+
&->( type, **options ) do
|
91
|
+
Not.new type, **options
|
92
|
+
end # .Not
|
93
|
+
|
94
|
+
# @!endgroup Negation Type Factories # ***************************************
|
95
|
+
|
96
|
+
|
97
|
+
# /Namespace
|
98
|
+
# ========================================================================
|
99
|
+
|
100
|
+
end # module NRSER
|
101
|
+
end #module Types
|
data/lib/nrser/types/numbers.rb
CHANGED
@@ -3,172 +3,227 @@ require 'nrser/types/is_a'
|
|
3
3
|
require 'nrser/types/combinators'
|
4
4
|
require 'nrser/types/bounded'
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
#
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
6
|
+
|
7
|
+
# Namespace
|
8
|
+
# ========================================================================
|
9
|
+
|
10
|
+
module NRSER
|
11
|
+
module Types
|
12
|
+
|
13
|
+
|
14
|
+
# Definitions
|
15
|
+
# ========================================================================
|
16
|
+
|
17
|
+
|
18
|
+
# Parse a string into a number.
|
19
|
+
#
|
20
|
+
# @return [Integer]
|
21
|
+
# If the string represents a whole integer.
|
22
|
+
#
|
23
|
+
# @return [Float]
|
24
|
+
# If the string represents a decimal number.
|
25
|
+
#
|
26
|
+
def self.parse_number string
|
27
|
+
float = Float string
|
28
|
+
int = float.to_i
|
29
|
+
if float == int then int else float end
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
# @!group Number Type Factories
|
34
|
+
# ----------------------------------------------------------------------------
|
35
|
+
|
36
|
+
# @!method self.Numeric **options
|
37
|
+
# The Ruby {Numeric} type, which is the super-class of all number classes:
|
38
|
+
# {Integer}, {Float}, {Rational}, {Complex}.
|
39
|
+
#
|
40
|
+
# In set theory notation this would either be expressed as either:
|
41
|
+
#
|
42
|
+
# 1. ℤ ∪ ℚ ∪ ℝ ∪ ℂ
|
43
|
+
# 2. ℂ
|
44
|
+
#
|
45
|
+
# depending on how you want to thing about the embeddability of the sets
|
46
|
+
# within each other (ℤ is embeddable in ℚ, which is embeddable in ℝ, which
|
47
|
+
# is embeddable in ℂ).
|
48
|
+
#
|
49
|
+
# However, I feel like (2) is not at all useful for expressing the type,
|
50
|
+
# and I feel like the default of just using the {Type#name} as the
|
51
|
+
# {Type#symbolic} is easier to read than (1), so this type does not provide
|
52
|
+
# a `symbolic:` keyword argument.
|
53
|
+
#
|
54
|
+
# @param [Hash] options
|
55
|
+
# Passed to {Type#initialize}.
|
56
|
+
#
|
57
|
+
# @return [Type]
|
58
|
+
# A type whose members are all instances of Ruby's {Numeric} class.
|
59
|
+
#
|
60
|
+
def_type :Numeric,
|
61
|
+
aliases: [ :num, :number, :numeric ],
|
62
|
+
# symbolic: [ INTEGERS,
|
63
|
+
# RATIONALS,
|
64
|
+
# REALS,
|
65
|
+
# COMPLEXES ].join( " #{ UNION } " ),
|
66
|
+
from_s: method( :parse_number ),
|
67
|
+
&->( **options ) do
|
68
|
+
IsA.new Numeric, **options
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
# Integers
|
73
|
+
# =====================================================================
|
74
|
+
|
75
|
+
# @!method self.Integer **options
|
76
|
+
# Instances of the built-in {Integer} class.
|
77
|
+
#
|
78
|
+
# @param [Hash] options
|
79
|
+
# Passed to {Type#initialize}.
|
80
|
+
#
|
81
|
+
# @return [Type]
|
82
|
+
#
|
83
|
+
def_type :Integer,
|
84
|
+
symbolic: 'ℤ',
|
85
|
+
from_s: method( :parse_number ),
|
86
|
+
aliases: [ :int,
|
87
|
+
:integer,
|
88
|
+
:signed ],
|
89
|
+
&->( **options ) do
|
90
|
+
IsA.new Integer, **options
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
# Bounded Integers
|
95
|
+
# ---------------------------------------------------------------------
|
96
|
+
|
97
|
+
# @!method self.PositiveInteger **options
|
98
|
+
# Integers greater than zero.
|
99
|
+
#
|
100
|
+
# @param [Hash] options
|
101
|
+
# Passed to {Type#initialize}.
|
102
|
+
#
|
103
|
+
# @return [Type]
|
104
|
+
#
|
105
|
+
def_type :PositiveInteger,
|
106
|
+
symbolic: 'ℤ⁺',
|
107
|
+
aliases: [ :pos_int,
|
108
|
+
:positive_int ],
|
109
|
+
&->( **options ) do
|
110
|
+
intersection \
|
111
|
+
self.Integer,
|
112
|
+
bounded( min: 1 ),
|
113
|
+
**options
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
# @!method self.NegativeInteger **options
|
118
|
+
# Integer less than zero.
|
119
|
+
#
|
120
|
+
# @param [Hash] options
|
121
|
+
# Passed to {Type#initialize}.
|
122
|
+
#
|
123
|
+
# @return [Type]
|
124
|
+
#
|
125
|
+
def_type :NegativeInteger,
|
126
|
+
symbolic: 'ℤ⁻',
|
127
|
+
aliases: [ :neg_int,
|
128
|
+
:negative_int ],
|
129
|
+
&->( **options ) do
|
130
|
+
intersection \
|
131
|
+
self.Integer,
|
132
|
+
self.Bounded( max: -1 ),
|
133
|
+
**options
|
134
|
+
end
|
135
|
+
|
136
|
+
|
137
|
+
# @!method self.NonNegativeInteger **options
|
138
|
+
# Positive integers and zero... but it seems more efficient to define these
|
139
|
+
# as bounded instead of a union.
|
140
|
+
#
|
141
|
+
# @param [Hash] options
|
142
|
+
# Passed to {Type#initialize}.
|
143
|
+
#
|
144
|
+
# @return [Type]
|
145
|
+
#
|
146
|
+
def_type :NonNegativeInteger,
|
147
|
+
symbolic: 'ℕ⁰',
|
148
|
+
aliases: [ :non_neg_int,
|
149
|
+
:unsigned,
|
150
|
+
:index,
|
151
|
+
:non_negative_int, ],
|
152
|
+
&->( **options ) do
|
153
|
+
intersection \
|
154
|
+
self.Integer,
|
155
|
+
self.Bounded( min: 0 ),
|
156
|
+
**options
|
157
|
+
end
|
158
|
+
|
159
|
+
|
160
|
+
# @!method self.NonPositiveInteger **options
|
161
|
+
# Negative integers and zero.
|
162
|
+
#
|
163
|
+
# @param [Hash] options
|
164
|
+
# Passed to {Type#initialize}.
|
165
|
+
#
|
166
|
+
# @return [Type]
|
167
|
+
#
|
168
|
+
def_type :NonPositiveInteger,
|
169
|
+
symbolic: '{0}∪ℤ⁻',
|
170
|
+
aliases: [ :non_pos_int,
|
171
|
+
:non_positive_int,
|
172
|
+
:non_positive_integer ],
|
173
|
+
&->( **options ) do
|
174
|
+
intersection \
|
175
|
+
self.Integer,
|
176
|
+
self.Bounded( max: 0 ),
|
177
|
+
**options
|
178
|
+
end
|
179
|
+
|
180
|
+
|
181
|
+
# Etc...
|
182
|
+
# ----------------------------------------------------------------------------
|
183
|
+
|
184
|
+
#@!method self.Unsigned16BitInteger **options
|
185
|
+
# Unsigned 16-bit {Integer} type.
|
186
|
+
#
|
187
|
+
# @param [Hash] options
|
188
|
+
# Passed to {Type#initialize}.
|
189
|
+
#
|
190
|
+
# @return [Type]
|
191
|
+
#
|
192
|
+
def_type :Unsigned16BitInteger,
|
193
|
+
symbolic: 'uint16',
|
194
|
+
aliases: [ :uint16,
|
195
|
+
:ushort ],
|
196
|
+
&->( **options ) do
|
197
|
+
intersection \
|
198
|
+
self.Integer,
|
199
|
+
self.Bounded( min: 0, max: ((2 ** 16) - 1) ),
|
200
|
+
**options
|
201
|
+
end
|
202
|
+
|
203
|
+
|
204
|
+
#@!method self.UNIXPort **options
|
205
|
+
# A valid UNIX port number {Integer}, which is a 16-bit unsigned integer
|
206
|
+
# that can ot be `0`.
|
207
|
+
#
|
208
|
+
# @param [Hash] options
|
209
|
+
# Passed to {Type#initialize}.
|
210
|
+
#
|
211
|
+
# @return [Type]
|
212
|
+
#
|
213
|
+
def_type :UNIXPort,
|
214
|
+
aliases: [ :port, ],
|
215
|
+
&->( **options ) do
|
216
|
+
intersection \
|
217
|
+
self.Integer,
|
218
|
+
self.Bounded( min: 1, max: (2**16 - 1) ),
|
219
|
+
**options
|
220
|
+
end
|
221
|
+
|
222
|
+
# @!endgroup Number Type Factories # *****************************************
|
223
|
+
|
224
|
+
|
225
|
+
# /Namespace
|
226
|
+
# ========================================================================
|
227
|
+
|
228
|
+
end # module Types
|
229
|
+
end # module NRSER
|