flex-cartesian 1.2 → 1.2.2
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +14 -1
- data/lib/flex-cartesian.rb +27 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a2ca7796b432b25c13982324959267a48475d5e9bce840b36309f976e05aa8f
|
4
|
+
data.tar.gz: c43b4a80cda5177c29cd7e07c186d6075fa2597ed3fe3e4e886e49b94b76ef49
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8271368f575fdd9dc460d6acb7d37678faf8071293738c9cf421ad7fa3dbc0bcf197590d79e57216cc20ee4b028ffa0b58f84b160dddb900b71d778ba93ef8e8
|
7
|
+
data.tar.gz: 4e55180b78619c9ad100c0b6e7db1b19cc7c74871936939340d53af7b6e01eba82bd2bd2e739e0e33c3ef334cfb66f75284aeae1ef2ca1dcebbe00f60eb5843a
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 1.2.2 - 2025-07-28
|
4
|
+
### Added
|
5
|
+
- .dimensions functionality extended to more granular formatting
|
6
|
+
|
7
|
+
## 1.2.1 - 2025-07-28
|
8
|
+
### Fixed
|
9
|
+
- When adding function, check if its namesake exists
|
10
|
+
|
3
11
|
## 1.2 - 2025-07-23
|
4
12
|
## Added
|
5
13
|
- Optional progress bar to the function command :run
|
data/README.md
CHANGED
@@ -211,6 +211,9 @@ puts "\nPrint Cartesian space as Markdown"
|
|
211
211
|
s.output(format: :markdown)
|
212
212
|
puts "\nPrint Cartesian space as CSV"
|
213
213
|
s.output(format: :csv)
|
214
|
+
puts "\nGranular output of Cartesian space dimensions: #{s.dimensions(values: false)}"
|
215
|
+
puts "\nGranular output of Cartesian vectors:"
|
216
|
+
s.cartesian { |v| puts s.dimensions(v, separator: ' ') }
|
214
217
|
|
215
218
|
|
216
219
|
|
@@ -435,7 +438,7 @@ Displays a progress bar using `ruby-progressbar`.
|
|
435
438
|
|
436
439
|
---
|
437
440
|
|
438
|
-
###
|
441
|
+
### Generate Output
|
439
442
|
```ruby
|
440
443
|
output(separator: " | ", colorize: false, align: true, format: :plain, limit: nil, file: nil)
|
441
444
|
```
|
@@ -455,6 +458,16 @@ Markdown example:
|
|
455
458
|
| 2 | "b" |
|
456
459
|
```
|
457
460
|
|
461
|
+
```ruby
|
462
|
+
dimensions(data = @dimensions, raw: false, separator: ', ', dimensions: true, values: true)
|
463
|
+
```
|
464
|
+
Generates formatted Cartesian dimensions or vectors of Cartesian space
|
465
|
+
- `data`: what to format, either Cartesian vector (usually `s.cartesian { |v| ... }) or entire Cartesian dimensions
|
466
|
+
- `raw`: if enabled, overrides any other formarring flags and returns the same as `.inspect`
|
467
|
+
- `separator`: how to separate individual components
|
468
|
+
- `dimensions`: whether or not show dimension names
|
469
|
+
- `values`: whether or not show value(s) associated with dimensions
|
470
|
+
|
458
471
|
---
|
459
472
|
|
460
473
|
### Import from JSON or YAML
|
data/lib/flex-cartesian.rb
CHANGED
@@ -25,11 +25,11 @@ module FlexOutput
|
|
25
25
|
end
|
26
26
|
|
27
27
|
class FlexCartesian
|
28
|
-
attr :dimensions
|
29
28
|
|
30
29
|
def initialize(dimensions = nil, path: nil, format: :json)
|
31
30
|
if dimensions && path
|
32
|
-
|
31
|
+
puts "Please specify either dimensions or path to dimensions"
|
32
|
+
exit
|
33
33
|
end
|
34
34
|
@dimensions = dimensions
|
35
35
|
@conditions = []
|
@@ -39,6 +39,18 @@ class FlexCartesian
|
|
39
39
|
import(path, format: format) if path
|
40
40
|
end
|
41
41
|
|
42
|
+
def dimensions(data = @dimensions, raw: false, separator: ', ', dimensions: true, values: true)
|
43
|
+
return data.inspect if raw # by default, with no data speciaifed, we assume dimensions of Cartesian
|
44
|
+
return nil if not dimensions and not values
|
45
|
+
|
46
|
+
if data.is_a?(Struct) or data.is_a?(Hash) # vector in Cartesian or entire Cartesian
|
47
|
+
data.each_pair.map { |k, v| (dimensions ? "#{k}" : "") + ((dimensions and values) ? "=" : "") + (values ? "#{v}" : "") }.join(separator)
|
48
|
+
else
|
49
|
+
puts "Incorrect type of dimensions: #{data.class}"
|
50
|
+
exit
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
42
54
|
def cond(command = :print, index: nil, &block)
|
43
55
|
case command
|
44
56
|
when :set
|
@@ -114,6 +126,11 @@ end
|
|
114
126
|
|
115
127
|
def add_function(name, &block)
|
116
128
|
raise ArgumentError, "Block required" unless block_given?
|
129
|
+
if reserved_function_names.include?(name.to_sym)
|
130
|
+
raise ArgumentError, "Function name '#{name}' has been already added"
|
131
|
+
elsif reserved_struct_names.include?(name.to_sym)
|
132
|
+
raise ArgumentError, "Name '#{name}' has been reserved for internal method, you can't use it for a function"
|
133
|
+
end
|
117
134
|
@derived[name.to_sym] = block
|
118
135
|
end
|
119
136
|
|
@@ -282,6 +299,14 @@ end
|
|
282
299
|
|
283
300
|
private
|
284
301
|
|
302
|
+
def reserved_struct_names
|
303
|
+
(base_struct_methods = Struct.new(:dummy).methods(false) + Struct.new(:dummy).instance_methods(false)).uniq
|
304
|
+
end
|
305
|
+
|
306
|
+
def reserved_function_names
|
307
|
+
(self.methods + self.class.instance_methods(false)).uniq
|
308
|
+
end
|
309
|
+
|
285
310
|
def fmt_cell(value, colorize, width = nil)
|
286
311
|
str = case value
|
287
312
|
when String then value
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flex-cartesian
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yury Rassokhin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-07-
|
11
|
+
date: 2025-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|