flex-cartesian 0.1.1 → 0.1.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
- metadata +50 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96675f38efe3e792ac84749a93c495b5770de5b0b918331274b9f53999940a7a
|
4
|
+
data.tar.gz: 0313d03ed02f6e568a803403628fdf1dedf5af9b883575d702b15a12dbf166dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6bd8c8a7dca528707bb800b7f2fed94c6fe0fbcd1fcc2e114eb00d66505f8928a0afd88e7e38794d21cbe1c2be3813d9d43d7232b3e1d37583d0d19910ff1694
|
7
|
+
data.tar.gz: 16049ce389e509ca7264ea1b5752c6bd539270d63f211cf95e08a386bf9a3f6d67ba5615cb6fc4efca9033a01a70b1bd631b083f2f2ad6614f29850d2fe68ea7
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flex-cartesian
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yury Rassokhin
|
@@ -66,9 +66,55 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
description:
|
70
|
-
|
71
|
-
|
69
|
+
description: |
|
70
|
+
Flexible and human-friendly Cartesian product enumerator for Ruby.
|
71
|
+
Supports dimension-agnostic iteration, named dimensions, structured output,
|
72
|
+
lazy/eager evaluation, progress bar, JSON/YAML loading, and export to Markdown/CSV.
|
73
|
+
|
74
|
+
Example:
|
75
|
+
|
76
|
+
require 'flex-cartesian'
|
77
|
+
|
78
|
+
# Define Cartesian space with named dimensions:
|
79
|
+
example = {
|
80
|
+
dim1: [1, 2],
|
81
|
+
dim2: ['x', 'y'],
|
82
|
+
dim3: [true, false]
|
83
|
+
}
|
84
|
+
s = FlexCartesian.new(example)
|
85
|
+
|
86
|
+
# Iterate over all combinations and calculate function on each combination:
|
87
|
+
s.cartesian { |v| puts "#{v.dim1}-#{v.dim2}" if v.dim3 }
|
88
|
+
|
89
|
+
# Get number of Cartesian combinations:
|
90
|
+
puts "Total size: #{s.size}"
|
91
|
+
|
92
|
+
# Convert Cartesian space to array of combinations
|
93
|
+
array = s.to_a(limit: 3)
|
94
|
+
puts array.inspect
|
95
|
+
|
96
|
+
def do_something(v)
|
97
|
+
end
|
98
|
+
|
99
|
+
# Display progress bar (useful for large Cartesian spaces)
|
100
|
+
s.progress_each { |v| do_something(v) }
|
101
|
+
|
102
|
+
# Print Cartesian space as table
|
103
|
+
s.output(align: true)
|
104
|
+
|
105
|
+
# Lazy evaluation without materializing entire Cartesian product in memory:
|
106
|
+
s.cartesian(lazy: true).take(2).each { |v| puts v.inspect }
|
107
|
+
|
108
|
+
# Load from JSON or YAML
|
109
|
+
File.write('example.json', JSON.pretty_generate(example))
|
110
|
+
s = FlexCartesian.from_json('example.json')
|
111
|
+
s.output
|
112
|
+
|
113
|
+
# Export to Markdown
|
114
|
+
s.output(format: :markdown, align: true)
|
115
|
+
|
116
|
+
# Export to CSV
|
117
|
+
s.output(format: :csv)
|
72
118
|
email:
|
73
119
|
- yuri.rassokhin@gmail.com
|
74
120
|
executables: []
|