true_table 0.2.1 → 0.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/README.md +1 -0
- data/lib/true_table/version.rb +3 -0
- data/lib/true_table.rb +23 -13
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 842b30f634d0113dac1917cacac6b6cf4265a3bb50b37361aa8ae4f36bd4fec6
|
4
|
+
data.tar.gz: b15972166d48d756538b22e4074f3700d862460f0e5412ce12463261998bb3da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 502b4c1018f441800f298a45b0cc0bfe61ae1e6f528e2178839492e2d08206d85e0672cbc0f849e47f3f4d91433fcc97f060406a8bad949453b862983cc1a31b
|
7
|
+
data.tar.gz: ea29b5abe5a3f090db4932ba64daa42d89bc8f9413ec5c8db225ce521bfd662443e619726269e4f7bba2d53c35620c093553b7b138e3bd577a6046f87a351d45
|
data/README.md
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
[](https://badge.fury.io/rb/true_table)
|
4
4
|
[](https://github.com/DannyBen/true_table/actions?query=workflow%3ATest)
|
5
|
+
[](https://codeclimate.com/github/DannyBen/true_table/maintainability)
|
5
6
|
|
6
7
|
---
|
7
8
|
|
data/lib/true_table.rb
CHANGED
@@ -42,10 +42,10 @@ class TrueTable < Array
|
|
42
42
|
end
|
43
43
|
|
44
44
|
# Returns a new table without the specified columns
|
45
|
-
def -(
|
46
|
-
keep_keys = headers -
|
45
|
+
def -(other)
|
46
|
+
keep_keys = headers - other
|
47
47
|
result = self.class.new
|
48
|
-
each_row { |row,
|
48
|
+
each_row { |row, _i| result << row.slice(*keep_keys) }
|
49
49
|
result
|
50
50
|
end
|
51
51
|
|
@@ -83,7 +83,7 @@ class TrueTable < Array
|
|
83
83
|
|
84
84
|
# Removes rows with nil in any column
|
85
85
|
def compact!
|
86
|
-
delete_if { |row| row.
|
86
|
+
delete_if { |row| row.has_value?(nil) }
|
87
87
|
end
|
88
88
|
|
89
89
|
# Delete a row or a column in place and returns the deleted row/column
|
@@ -91,7 +91,8 @@ class TrueTable < Array
|
|
91
91
|
if index.is_a?(Symbol) || index.is_a?(String)
|
92
92
|
result = self[index]
|
93
93
|
return nil unless result
|
94
|
-
|
94
|
+
|
95
|
+
each_row { |row, _i| row.delete index }
|
95
96
|
result
|
96
97
|
else
|
97
98
|
super
|
@@ -109,9 +110,9 @@ class TrueTable < Array
|
|
109
110
|
def dig(*indexes)
|
110
111
|
key = indexes.shift
|
111
112
|
if key.is_a?(Symbol)
|
112
|
-
col(key.to_sym).dig
|
113
|
+
col(key.to_sym).dig(*indexes)
|
113
114
|
else
|
114
|
-
row(key).dig
|
115
|
+
row(key).dig(*indexes)
|
115
116
|
end
|
116
117
|
end
|
117
118
|
|
@@ -197,6 +198,11 @@ class TrueTable < Array
|
|
197
198
|
File.write path, to_csv
|
198
199
|
end
|
199
200
|
|
201
|
+
# Saves the table as a TSV file
|
202
|
+
def save_tsv(path)
|
203
|
+
File.write path, to_tsv
|
204
|
+
end
|
205
|
+
|
200
206
|
# Returns a new table with selected rows
|
201
207
|
def select
|
202
208
|
self.class.new super
|
@@ -210,7 +216,7 @@ class TrueTable < Array
|
|
210
216
|
|
211
217
|
# Returns a new table slice
|
212
218
|
def slice(*args)
|
213
|
-
if args.count == 1
|
219
|
+
if (args.count == 1) && args.first.is_a?(Integer)
|
214
220
|
super
|
215
221
|
else
|
216
222
|
self.class.new super
|
@@ -219,7 +225,7 @@ class TrueTable < Array
|
|
219
225
|
|
220
226
|
# Deletes and returns one more rows
|
221
227
|
def slice!(*args)
|
222
|
-
if args.count == 1
|
228
|
+
if (args.count == 1) && args.first.is_a?(Integer)
|
223
229
|
super
|
224
230
|
else
|
225
231
|
self.class.new super
|
@@ -247,19 +253,24 @@ class TrueTable < Array
|
|
247
253
|
end
|
248
254
|
|
249
255
|
# Returns a CSV string
|
250
|
-
def to_csv(row_separator = "\n", col_separator =
|
256
|
+
def to_csv(row_separator = "\n", col_separator = ',')
|
257
|
+
join(row_separator, col_separator, with_headers: true)
|
258
|
+
end
|
259
|
+
|
260
|
+
# Returns a TSV string
|
261
|
+
def to_tsv(row_separator = "\n", col_separator = "\t")
|
251
262
|
join(row_separator, col_separator, with_headers: true)
|
252
263
|
end
|
253
264
|
|
254
265
|
# Returns a hash representation of the table using the values of the
|
255
266
|
# first column as hash keys
|
256
267
|
def to_h
|
257
|
-
|
268
|
+
super { |row| [row.values.first, row] }
|
258
269
|
end
|
259
270
|
|
260
271
|
# Returns only values, without any headers (array of arrays)
|
261
272
|
def values
|
262
|
-
map
|
273
|
+
map(&:values)
|
263
274
|
end
|
264
275
|
|
265
276
|
protected
|
@@ -270,5 +281,4 @@ protected
|
|
270
281
|
self[i][key] = value
|
271
282
|
end
|
272
283
|
end
|
273
|
-
|
274
284
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: true_table
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danny Ben Shitrit
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Simple and intuitive tabular data type
|
14
14
|
email: db@dannyben.com
|
@@ -18,10 +18,12 @@ extra_rdoc_files: []
|
|
18
18
|
files:
|
19
19
|
- README.md
|
20
20
|
- lib/true_table.rb
|
21
|
+
- lib/true_table/version.rb
|
21
22
|
homepage: https://github.com/dannyben/true_table
|
22
23
|
licenses:
|
23
24
|
- MIT
|
24
|
-
metadata:
|
25
|
+
metadata:
|
26
|
+
rubygems_mfa_required: 'true'
|
25
27
|
post_install_message:
|
26
28
|
rdoc_options: []
|
27
29
|
require_paths:
|
@@ -37,7 +39,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
37
39
|
- !ruby/object:Gem::Version
|
38
40
|
version: '0'
|
39
41
|
requirements: []
|
40
|
-
rubygems_version: 3.
|
42
|
+
rubygems_version: 3.3.26
|
41
43
|
signing_key:
|
42
44
|
specification_version: 4
|
43
45
|
summary: Simple and intuitive tabular data type
|