texttable 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/texttable.rb +58 -0
- data/texttable.gemspec +1 -1
- 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: 4fd483aa1f36230c2afe01d2a2dd26459506bc730e66187686ed83e6f43bfd20
|
4
|
+
data.tar.gz: c175539e6e2bc57f15f06f37a204079d2a13a70b5d29eeacc09b3fed30f16836
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eea9d1c329bed3b186cc2141bb7cc9e8196e6cf9ce76077c39462e92f5cd8fc3f57b577d33030beafad51c239c47688215b59a788b44a7c2635f31a7991e80db
|
7
|
+
data.tar.gz: 5e17657bc436e6b7906364d0b7dcefbf4d6400976b5da98cdda360fe4888e9ddadc8c104da8d59078c77d966d876cb695faf2ff4aeb5ba9be3b6fa7256b71508
|
data/lib/texttable.rb
CHANGED
@@ -4,6 +4,64 @@ class TextTable
|
|
4
4
|
def initialize
|
5
5
|
@cols = Hash.new{|h,k| h[k] = h.size}
|
6
6
|
@rows = []
|
7
|
+
@vals = nil
|
8
|
+
@row = 0
|
9
|
+
end
|
10
|
+
|
11
|
+
def index(field)
|
12
|
+
case field
|
13
|
+
when String, Symbol
|
14
|
+
field = field.to_s
|
15
|
+
index = @cols[field] || @cols[field.downcase.gsub(/\W/,'_')]
|
16
|
+
index
|
17
|
+
when Numeric
|
18
|
+
field
|
19
|
+
else
|
20
|
+
raise "invalid field index #{field.inspect}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def [](key, val=nil)
|
25
|
+
@vals ||= @rows[@row]
|
26
|
+
index = index(key)
|
27
|
+
value = @vals[index] if index
|
28
|
+
value.nil? ? val : value
|
29
|
+
end
|
30
|
+
|
31
|
+
def row(row=nil)
|
32
|
+
row or return @row
|
33
|
+
@vals = @rows[@row = row]
|
34
|
+
self
|
35
|
+
end
|
36
|
+
|
37
|
+
def row=(row)
|
38
|
+
@vals = @rows[@row = row]
|
39
|
+
@row
|
40
|
+
end
|
41
|
+
|
42
|
+
def vals
|
43
|
+
@vals ||= @rows[@row]
|
44
|
+
end
|
45
|
+
|
46
|
+
def each
|
47
|
+
@rows or raise "no rows defined"
|
48
|
+
@rows.each_with_index {|_, row| yield(row(row)) }
|
49
|
+
end
|
50
|
+
|
51
|
+
def method_missing(field, *args)
|
52
|
+
field = field.to_s
|
53
|
+
equal = field.chomp!("=")
|
54
|
+
index = index(field)
|
55
|
+
if equal
|
56
|
+
index ||= @cols[field]
|
57
|
+
value = vals[index] = args.first
|
58
|
+
elsif index
|
59
|
+
raise "variable lookup ignores arguments" unless args.empty?
|
60
|
+
value = vals[index]
|
61
|
+
else
|
62
|
+
value = ""
|
63
|
+
end
|
64
|
+
value == false ? value : (value || "")
|
7
65
|
end
|
8
66
|
|
9
67
|
def add(hash)
|
data/texttable.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: texttable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Shreeve
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: This gem will auto-size based on column widths.
|
14
14
|
email: steve.shreeve@gmail.com
|