vector_number 0.4.3 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,57 +1,37 @@
1
- type vector_type = VectorNumber
2
- type real_number = Integer | Float | Rational | BigDecimal
3
-
4
- type in_value_type = untyped
5
- type unit_type = untyped
6
- type coefficient_type = real_number
1
+ # A class to add together anything.
2
+ class VectorNumber
3
+ # ---- Generic types ----
4
+ type real_number = Integer | Float | Rational | BigDecimal
7
5
 
8
- type list[T] = Array[T]
6
+ type in_value_type = untyped
7
+ type unit_type = untyped
8
+ type coefficient_type = real_number
9
9
 
10
- type plain_vector_type = Hash[unit_type, coefficient_type]
11
- type units_list_type = list[unit_type]
12
- type coefficients_list_type = list[coefficient_type]
13
- type each_value_type = [unit_type, coefficient_type]
10
+ type list[T] = Array[T]
14
11
 
15
- type options_type = Hash[Symbol, untyped]
12
+ type plain_instance = Hash[unit_type, coefficient_type]
13
+ type units_list_type = list[unit_type]
14
+ type coefficients_list_type = list[coefficient_type]
15
+ type each_value_type = [unit_type, coefficient_type]
16
16
 
17
- interface _BaseMethods
18
- def size: -> Integer
19
- def options: -> options_type
17
+ # ---- Constants ----
20
18
 
21
- # private
22
- def new: () { (coefficient_type value) -> coefficient_type } -> vector_type
23
- | (in_value_type) { (coefficient_type value) -> coefficient_type } -> vector_type
24
- | () -> vector_type
25
- | (in_value_type) -> vector_type
26
- def real_number?: (real_number value) -> true
27
- | (vector_type) -> bool
28
- | (in_value_type value) -> false
29
- end
19
+ VERSION: String
30
20
 
31
- # A class to add together anything.
32
- class VectorNumber
33
- include _BaseMethods
34
- include VectorNumber::Mathing
35
- include VectorNumber::MathConverting
36
- include VectorNumber::Converting
37
- include VectorNumber::Enumerating
38
- include VectorNumber::Comparing
39
- include VectorNumber::Querying
40
- include VectorNumber::Stringifying
21
+ NUMERIC_UNITS: list[SpecialUnit]
22
+ R: SpecialUnit
23
+ I: SpecialUnit
41
24
 
42
- VERSION: String
25
+ # ---- Public methods ----
43
26
 
44
- KNOWN_OPTIONS: list[Symbol]
45
- DEFAULT_OPTIONS: options_type
27
+ def self.[]: (*unit_type values) -> instance
46
28
 
47
- UNIT: ^(Integer) -> Complex
48
- R: Complex
49
- I: Complex
29
+ def self.numeric_unit?: (unit_type unit) -> bool
50
30
 
51
- def self.[]: (*unit_type values, **options_type options) -> vector_type
31
+ def size: -> Integer
52
32
 
53
33
  def initialize:
54
- (?(units_list_type | plain_vector_type | vector_type)? values, ?options_type? options)
34
+ (?(units_list_type | plain_instance | instance)? values)
55
35
  ?{ (coefficient_type coefficient) -> coefficient_type }
56
36
  -> void
57
37
 
@@ -63,197 +43,179 @@ class VectorNumber
63
43
  private
64
44
 
65
45
  @size: Integer
66
- @options: options_type
67
- @data: plain_vector_type
46
+ @data: plain_instance
47
+
48
+ def new: () { (coefficient_type value) -> coefficient_type } -> instance
49
+ | (in_value_type) { (coefficient_type value) -> coefficient_type } -> instance
50
+ | () -> instance
51
+ | (in_value_type) -> instance
52
+
53
+ def real_number?: (real_number value) -> true
54
+ | (instance) -> bool
55
+ | (in_value_type value) -> false
68
56
 
69
- def initialize_from: ((units_list_type | plain_vector_type | vector_type)? values) -> void
57
+ def initialize_from: ((units_list_type | plain_instance | instance)? values) -> void
70
58
 
71
- def add_value_to_data: ((vector_type | Numeric | unit_type) value) -> void
59
+ def add_value_to_data: ((instance | Numeric | unit_type) value) -> void
72
60
 
73
61
  def add_numeric_value_to_data: (Numeric value) -> void
74
62
 
75
- def add_vector_to_data: ((vector_type | plain_vector_type) vector) -> void
63
+ def add_vector_to_data: ((instance | plain_instance) vector) -> void
76
64
 
77
65
  def apply_transform: () ?{ (coefficient_type value) -> coefficient_type } -> void
78
66
 
79
- def save_options: (options_type? options, values: in_value_type) -> void
80
- def merge_options: (options_type base_options, options_type added_options) -> options_type
81
- def default_options: () -> options_type
82
- def known_options: () -> list[Symbol]
83
-
84
67
  def finalize_contents: () -> void
68
+ end
85
69
 
86
- # Methods for performing actual math.
87
- module Mathing
88
- include _BaseMethods
89
-
90
- def coerce: (in_value_type) -> [vector_type, self]
91
-
92
- def -@: () -> vector_type
93
- alias neg -@
94
-
95
- def +: (in_value_type) -> vector_type
96
- alias add +
97
-
98
- def -: (in_value_type) -> vector_type
99
- alias sub -
100
-
101
- def *: (real_number | vector_type) -> vector_type
102
- alias mult *
70
+ # Methods for performing actual math.
71
+ class VectorNumber
72
+ def coerce: (in_value_type) -> [instance, self]
103
73
 
104
- def /: (real_number | vector_type) -> vector_type
105
- alias quo /
74
+ def -@: () -> instance
75
+ alias neg -@
106
76
 
107
- def fdiv: (real_number | vector_type) -> vector_type
77
+ def +: (in_value_type) -> instance
78
+ alias add +
108
79
 
109
- def div: (real_number | vector_type) -> vector_type
80
+ def -: (in_value_type) -> instance
81
+ alias sub -
110
82
 
111
- def %: (real_number | vector_type) -> vector_type
112
- alias modulo %
83
+ def *: (real_number | instance) -> instance
84
+ alias mult *
113
85
 
114
- def divmod: (real_number | vector_type) -> [vector_type, vector_type]
86
+ def /: (real_number | instance) -> instance
87
+ alias quo /
115
88
 
116
- def remainder: (real_number | vector_type) -> vector_type
89
+ def fdiv: (real_number | instance) -> instance
117
90
 
118
- private
91
+ def div: (real_number | instance) -> instance
119
92
 
120
- def check_divisibility: (real_number | vector_type) -> void
121
- end
93
+ def %: (real_number | instance) -> instance
94
+ alias modulo %
122
95
 
123
- # Various mathematical operations that are also conversions.
124
- module MathConverting
125
- include _BaseMethods
126
- include Enumerating
96
+ def divmod: (real_number | instance) -> [instance, instance]
127
97
 
128
- def abs: () -> Float
98
+ def remainder: (real_number | instance) -> instance
129
99
 
130
- def abs2: () -> Float
131
-
132
- def truncate: (Integer) -> vector_type
100
+ private
133
101
 
134
- def ceil: (Integer) -> vector_type
102
+ def check_divisibility: (real_number | instance) -> void
103
+ end
135
104
 
136
- def floor: (Integer) -> vector_type
105
+ # Various mathematical operations that are also conversions.
106
+ class VectorNumber
107
+ def abs: () -> Float
137
108
 
138
- def round: (Integer, ?half: (:up | :down | :even)) -> vector_type
139
- end
109
+ def abs2: () -> Float
140
110
 
141
- # Methods for converting to different number classes.
142
- module Converting
143
- include _BaseMethods
144
- include Querying
111
+ def truncate: (?Integer) -> instance
145
112
 
146
- def real: () -> real_number
113
+ def ceil: (?Integer) -> instance
147
114
 
148
- def imaginary: () -> real_number
149
- alias imag imaginary
115
+ def floor: (?Integer) -> instance
150
116
 
151
- def to_i: () -> Integer
152
- | () -> void
153
- alias to_int to_i
117
+ def round: (?Integer, ?half: (:up | :down | :even)) -> instance
118
+ end
154
119
 
155
- def to_f: () -> Float
156
- | () -> void
120
+ # Methods for converting to different number classes.
121
+ class VectorNumber
122
+ def real: () -> real_number
157
123
 
158
- def to_r: () -> Rational
159
- | () -> void
124
+ def imaginary: () -> real_number
125
+ alias imag imaginary
160
126
 
161
- def to_d: (?Integer?) -> BigDecimal
162
- | (?Integer?) -> void
127
+ def to_i: () -> Integer
128
+ alias to_int to_i
163
129
 
164
- def to_c: () -> Complex
165
- | () -> void
130
+ def to_f: () -> Float
166
131
 
167
- def truncate: (?Integer digits) -> vector_type
132
+ def to_r: () -> Rational
168
133
 
169
- private
134
+ def to_d: (?Integer?) -> BigDecimal
170
135
 
171
- def raise_convert_error: (Class) -> void
172
- end
136
+ def to_c: () -> Complex
173
137
 
174
- # Methods for enumerating values of the number.
175
- module Enumerating
176
- include _BaseMethods
177
- include _Each[each_value_type]
178
- include Enumerable[each_value_type]
138
+ private
179
139
 
180
- def each: () { (unit_type unit, coefficient_type coefficient) -> void } -> self
181
- | () -> Enumerator[each_value_type, Integer]
182
- | ...
183
- alias each_pair each
140
+ def raise_convert_error: (Class) -> void
141
+ end
184
142
 
185
- def units: () -> units_list_type
186
- alias keys units
143
+ class VectorNumber
144
+ include _Each[each_value_type]
145
+ include Enumerable[each_value_type]
187
146
 
188
- def coefficients: () -> coefficients_list_type
189
- alias values coefficients
147
+ def each: () { (unit_type unit, coefficient_type coefficient) -> void } -> self
148
+ | () -> Enumerator[each_value_type, Integer]
149
+ | ...
150
+ alias each_pair each
190
151
 
191
- def to_h: () -> plain_vector_type
192
- | () { (unit_type, coefficient_type) -> each_value_type } -> plain_vector_type
152
+ def units: () -> units_list_type
153
+ alias keys units
193
154
 
194
- def []: (unit_type unit) -> coefficient_type
155
+ def coefficients: () -> coefficients_list_type
156
+ alias values coefficients
195
157
 
196
- def unit?: (unit_type unit) -> bool
197
- alias key? unit?
198
- end
158
+ def to_h: () -> plain_instance
159
+ | () { (unit_type, coefficient_type) -> each_value_type } -> plain_instance
199
160
 
200
- # Methods for comparing with other numbers.
201
- module Comparing
202
- include _BaseMethods
203
- include Enumerating
204
- include Converting
205
- include Querying
161
+ def []: (unit_type unit) -> coefficient_type
206
162
 
207
- def ==: (in_value_type other) -> bool
163
+ def unit?: (unit_type unit) -> bool
164
+ alias key? unit?
165
+ end
208
166
 
209
- def eql?: (in_value_type other) -> bool
167
+ # Methods for comparing with other numbers.
168
+ class VectorNumber
169
+ def ==: (in_value_type other) -> bool
210
170
 
211
- def hash: () -> Integer
171
+ def eql?: (in_value_type other) -> bool
212
172
 
213
- def <=>: (in_value_type other) -> Integer?
214
- end
173
+ def hash: () -> Integer
215
174
 
216
- # Methods for querying state of the number.
217
- # Mostly modeled after {::Complex}.
218
- module Querying
219
- include Enumerating
175
+ def <=>: (in_value_type other) -> Integer?
176
+ end
220
177
 
221
- def numeric?: (?Integer) -> bool
178
+ # Methods for querying state of the number.
179
+ # Mostly modeled after {::Complex}.
180
+ class VectorNumber
181
+ def numeric?: (?Integer) -> bool
222
182
 
223
- def nonnumeric?: (?Integer) -> bool
183
+ def nonnumeric?: (?Integer) -> bool
224
184
 
225
- def finite?: () -> bool
185
+ def finite?: () -> bool
226
186
 
227
- def infinite?: () -> Integer?
187
+ def infinite?: () -> Integer?
228
188
 
229
- def zero?: () -> bool
189
+ def zero?: () -> bool
230
190
 
231
- def nonzero?: () -> self?
191
+ def nonzero?: () -> self?
232
192
 
233
- def positive?: () -> bool
193
+ def positive?: () -> bool
234
194
 
235
- def negative?: () -> bool
195
+ def negative?: () -> bool
236
196
 
237
- def real?: () -> false
197
+ def real?: () -> false
238
198
 
239
- def integer?: () -> false
240
- end
199
+ def integer?: () -> false
200
+ end
241
201
 
242
- # Methods and options for string representation.
243
- module Stringifying
244
- include Querying
202
+ # Methods and options for string representation.
203
+ class VectorNumber
204
+ MULT_STRINGS: Hash[Symbol, String]
245
205
 
246
- MULT_STRINGS: Hash[Symbol, String]
206
+ def to_s: (?mult: (Symbol | String)) { (unit_type, coefficient_type, ?Integer index, ?String operator) -> String } -> String
247
207
 
248
- def to_s: (?mult: (Symbol | String)) -> String
208
+ def inspect: () -> String
249
209
 
250
- def inspect: () -> String
210
+ private
251
211
 
252
- private
212
+ def build_string: (String operator) -> String
213
+ | (String operator) { (unit_type, coefficient_type, ?Integer index, ?String operator) -> String } -> String
253
214
 
254
- def value_to_s: (unit_type unit, coefficient_type coefficient, mult: (Symbol | String)) -> String
255
- end
215
+ def value_to_s: (unit_type unit, coefficient_type coefficient, String operator) -> String
216
+ end
256
217
 
218
+ class VectorNumber
257
219
  # Refinements of Numeric classes to better work with VectorNumber and similar classes.
258
220
  module NumericRefinements
259
221
  module CommutativeShuttle
@@ -266,3 +228,14 @@ class VectorNumber
266
228
  end
267
229
  end
268
230
  end
231
+
232
+ class VectorNumber
233
+ # Class for representing special numerical units.
234
+ class SpecialUnit
235
+ def initialize: (Object unit, String text) -> void
236
+
237
+ def to_s: () -> String
238
+
239
+ def inspect: () -> String
240
+ end
241
+ end
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vector_number
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
- - Alexandr Bulancov
7
+ - Alexander Bulancov
8
8
  bindir: exe
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
@@ -13,18 +13,20 @@ description: |
13
13
  VectorNumber provides a Numeric-like experience for doing arithmetics on heterogeneous objects, with more advanced operations based on real vector spaces available when needed.
14
14
 
15
15
  Features:
16
- - Add and subtract (almost) any object, with no setup or declaration.
17
- - Multiply and divide vectors by any real number to create 1.35 of an array and -2 of a string. What does that mean? Only you know!
18
- - Use vectors instead of inbuilt numbers in most situtations with no difference in behavior. Or, use familiar methods from numerics with sane semantics!
19
- - Enumerate vectors in a hash-like fashion, or transform to an array or hash as needed.
20
- - Enjoy a mix of vector-, complex- and polynomial-like behavior at appropriate times.
21
- - No dependencies, no extensions. It just works!
16
+ * Add and subtract (almost) any object, with no setup or declaration.
17
+ * Multiply and divide vectors by any real number to create 1.35 of an array and -2 of a string. What does that mean? Only you know!
18
+ * Use vectors instead of inbuilt numbers in most situtations with no difference in behavior. Or, use familiar methods from numerics with sane semantics!
19
+ * Enumerate vectors in a hash-like fashion, or transform to an array or hash as needed.
20
+ * Enjoy a mix of vector-, complex- and polynomial-like behavior at appropriate times.
21
+ * No dependencies, no extensions. It just works!
22
22
  executables: []
23
23
  extensions: []
24
24
  extra_rdoc_files:
25
25
  - README.md
26
+ - doc/vector_space.svg
26
27
  files:
27
28
  - README.md
29
+ - doc/vector_space.svg
28
30
  - lib/vector_number.rb
29
31
  - lib/vector_number/comparing.rb
30
32
  - lib/vector_number/converting.rb
@@ -33,6 +35,7 @@ files:
33
35
  - lib/vector_number/mathing.rb
34
36
  - lib/vector_number/numeric_refinements.rb
35
37
  - lib/vector_number/querying.rb
38
+ - lib/vector_number/special_unit.rb
36
39
  - lib/vector_number/stringifying.rb
37
40
  - lib/vector_number/version.rb
38
41
  - sig/vector_number.rbs
@@ -42,9 +45,9 @@ licenses:
42
45
  metadata:
43
46
  homepage_uri: https://github.com/trinistr/vector_number
44
47
  bug_tracker_uri: https://github.com/trinistr/vector_number/issues
45
- documentation_uri: https://rubydoc.info/gems/vector_number/0.4.3
46
- source_code_uri: https://github.com/trinistr/vector_number/tree/v0.4.3
47
- changelog_uri: https://github.com/trinistr/vector_number/blob/v0.4.3/CHANGELOG.md
48
+ documentation_uri: https://rubydoc.info/gems/vector_number/0.6.0
49
+ source_code_uri: https://github.com/trinistr/vector_number/tree/v0.6.0
50
+ changelog_uri: https://github.com/trinistr/vector_number/blob/v0.6.0/CHANGELOG.md
48
51
  rubygems_mfa_required: 'true'
49
52
  rdoc_options:
50
53
  - "--main"