true_table 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
- data/README.md +2 -1
- data/lib/true_table/table.rb +41 -4
- data/lib/true_table/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c778d54af435cbd53a4dfc45df1026d954dd79fda06c12ca7de9c5203054bd5
|
4
|
+
data.tar.gz: ecb8c574d6f53b7936cf7c668e55050f4effee32063922b92605200f48569d94
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9cc7983ee8202a8ce1c1e4414dc5e5a2c34f5ed4e70c2789e2c940c325431cb1034d99ddaaae6c11e7771b993b8f0f747c3e3a7a792445b22f6376573e02b638
|
7
|
+
data.tar.gz: 3f2e42e7b50716d0e93e0676fd7c161a8e6bab1962c50358b734fb301d7b967785acaa7db79382a1b70fffce28c54d6ed9e1e27a88e45c237db717c2ddca6ed5
|
data/README.md
CHANGED
data/lib/true_table/table.rb
CHANGED
@@ -7,7 +7,7 @@ module TrueTable
|
|
7
7
|
result
|
8
8
|
end
|
9
9
|
|
10
|
-
# Returns a new table without specified columns
|
10
|
+
# Returns a new table without the specified columns
|
11
11
|
def -(cols)
|
12
12
|
keep_keys = headers - cols
|
13
13
|
result = self.class.new
|
@@ -17,12 +17,17 @@ module TrueTable
|
|
17
17
|
|
18
18
|
# Returns a row or a column
|
19
19
|
def [](key)
|
20
|
-
key.is_a?(Symbol)
|
20
|
+
key.is_a?(Symbol) ? col(key) : super
|
21
21
|
end
|
22
22
|
|
23
23
|
# Adds or updates a row or a column
|
24
24
|
def []=(key, value)
|
25
|
-
key.is_a?(Symbol)
|
25
|
+
key.is_a?(Symbol) ? add_col(key.to_sym, value) : super
|
26
|
+
end
|
27
|
+
|
28
|
+
# Returns a deep copy of self
|
29
|
+
def clone
|
30
|
+
self.class.new map(&:clone)
|
26
31
|
end
|
27
32
|
|
28
33
|
# Returns a column as Array
|
@@ -69,7 +74,7 @@ module TrueTable
|
|
69
74
|
# Extracts nested value. Accepts row, column or column, row
|
70
75
|
def dig(*indexes)
|
71
76
|
key = indexes.shift
|
72
|
-
if key.is_a?(Symbol)
|
77
|
+
if key.is_a?(Symbol)
|
73
78
|
col(key.to_sym).dig *indexes
|
74
79
|
else
|
75
80
|
row(key).dig *indexes
|
@@ -84,6 +89,22 @@ module TrueTable
|
|
84
89
|
# Iterates over rows
|
85
90
|
alias each_row each_with_index
|
86
91
|
|
92
|
+
def fetch(key, *default)
|
93
|
+
if key.is_a?(Symbol)
|
94
|
+
if headers.include? key
|
95
|
+
col(key.to_sym)
|
96
|
+
elsif default.any?
|
97
|
+
default.first
|
98
|
+
elsif block_given?
|
99
|
+
yield key
|
100
|
+
else
|
101
|
+
raise IndexError, "row :#{key} does not exist"
|
102
|
+
end
|
103
|
+
else
|
104
|
+
super
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
87
108
|
# Returns an array of column headers
|
88
109
|
def headers
|
89
110
|
first.keys
|
@@ -119,6 +140,11 @@ module TrueTable
|
|
119
140
|
self.class.new super
|
120
141
|
end
|
121
142
|
|
143
|
+
# Returns a new table with the element at `count` as the first element
|
144
|
+
def rotate(count = 1)
|
145
|
+
self.class.new super
|
146
|
+
end
|
147
|
+
|
122
148
|
# Returns a row
|
123
149
|
alias row []
|
124
150
|
|
@@ -128,6 +154,11 @@ module TrueTable
|
|
128
154
|
end
|
129
155
|
alias filter select
|
130
156
|
|
157
|
+
# Returns a new shuffled tables
|
158
|
+
def shuffle(*args)
|
159
|
+
self.class.new super
|
160
|
+
end
|
161
|
+
|
131
162
|
# Returns a new sorted table
|
132
163
|
def sort
|
133
164
|
self.class.new super
|
@@ -143,6 +174,12 @@ module TrueTable
|
|
143
174
|
join(row_separator, col_separator, with_headers: true)
|
144
175
|
end
|
145
176
|
|
177
|
+
# Returns a hash representation of the table using the values of the
|
178
|
+
# first column as hash keys
|
179
|
+
def to_h
|
180
|
+
map { |row| [row.values.first, row] }.to_h
|
181
|
+
end
|
182
|
+
|
146
183
|
# Returns only values, without any headers (array of arrays)
|
147
184
|
def values
|
148
185
|
map { |row| row.values }
|
data/lib/true_table/version.rb
CHANGED
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.1.
|
4
|
+
version: 0.1.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: 2020-
|
11
|
+
date: 2020-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Simple and intuitive tabular data type
|
14
14
|
email: db@dannyben.com
|
@@ -32,7 +32,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
32
32
|
requirements:
|
33
33
|
- - ">="
|
34
34
|
- !ruby/object:Gem::Version
|
35
|
-
version: 2.
|
35
|
+
version: 2.7.0
|
36
36
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|