tabelr 0.0.7 → 0.0.8
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.
- data/README.md +17 -5
- data/bin/tabelr +28 -1
- data/lib/tabelr.rb +2 -30
- data/lib/tabelr/table_formater.rb +4 -5
- data/tabelr.gemspec +1 -1
- data/test/code_use.rb +34 -0
- metadata +4 -3
data/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
Tabelr
|
2
2
|
======
|
3
3
|
|
4
|
-
Creates neat aligned ascii tables from a json input
|
4
|
+
Creates neat aligned ascii tables from a json input.
|
5
5
|
|
6
|
-
This is mainly useful on
|
6
|
+
This is mainly useful on SQL query output from Sequel Pro app, which can save results as json.
|
7
7
|
|
8
8
|
I'm sure there are a 100+ versions of this around, but I wrote this mainly for the challenge.
|
9
9
|
|
@@ -11,10 +11,22 @@ I'm sure there are a 100+ versions of this around, but I wrote this mainly for t
|
|
11
11
|
Usage
|
12
12
|
-----
|
13
13
|
|
14
|
-
|
14
|
+
Command line :-
|
15
15
|
|
16
|
+
ruby bin/tabelr test/example.json test/output.txt
|
16
17
|
|
17
|
-
|
18
|
+
|
19
|
+
Code :
|
20
|
+
|
21
|
+
require 'tabelr'
|
22
|
+
|
23
|
+
data = {}
|
24
|
+
|
25
|
+
res = Tabelr::convert data
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
Input
|
18
30
|
-----
|
19
31
|
|
20
32
|
- The input must be a json formatted file
|
@@ -43,7 +55,7 @@ E.g. (extract from `test/example.json`)
|
|
43
55
|
"column4": 1241
|
44
56
|
},
|
45
57
|
|
46
|
-
|
58
|
+
Output
|
47
59
|
------
|
48
60
|
|
49
61
|
The output filename can be omitted, it will then default to the STDOUT terminal
|
data/bin/tabelr
CHANGED
@@ -2,4 +2,31 @@
|
|
2
2
|
|
3
3
|
require_relative '../lib/tabelr'
|
4
4
|
|
5
|
-
|
5
|
+
|
6
|
+
def parse_args args
|
7
|
+
commands = []
|
8
|
+
args.each do |arg|
|
9
|
+
commands << arg unless arg.index('-') === 0
|
10
|
+
end
|
11
|
+
commands
|
12
|
+
end
|
13
|
+
|
14
|
+
def valid? args
|
15
|
+
if args.nil? or args[0].nil?
|
16
|
+
puts "Man, you gotta give me a file to read from!"
|
17
|
+
return
|
18
|
+
end
|
19
|
+
unless File.exist?(args[0])
|
20
|
+
puts "Man, you gotta give me a valid file to read from!"
|
21
|
+
return
|
22
|
+
end
|
23
|
+
true
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
parsed_args = parse_args ARGV
|
28
|
+
raise unless valid? parsed_args
|
29
|
+
|
30
|
+
data = JSON.parse(File.read(parsed_args[0]))
|
31
|
+
puts Tabelr::convert(data)
|
32
|
+
|
data/lib/tabelr.rb
CHANGED
@@ -4,36 +4,8 @@ require_relative '../lib/tabelr/table_formater'
|
|
4
4
|
module Tabelr
|
5
5
|
class << self
|
6
6
|
|
7
|
-
def
|
8
|
-
|
9
|
-
return unless valid? args
|
10
|
-
|
11
|
-
@tf = TableFormator.new
|
12
|
-
|
13
|
-
json = JSON.parse(File.read(args[0]))
|
14
|
-
# output = STDOUT
|
15
|
-
output = $stdout
|
16
|
-
@tf.go json, output
|
17
|
-
end
|
18
|
-
|
19
|
-
def parse_args
|
20
|
-
commands = []
|
21
|
-
ARGV.each do |arg|
|
22
|
-
commands << arg unless arg.index('-') === 0
|
23
|
-
end
|
24
|
-
commands
|
25
|
-
end
|
26
|
-
|
27
|
-
def valid? args
|
28
|
-
if args.nil? or args[0].nil?
|
29
|
-
puts "Man, you gotta give me a file to read from!"
|
30
|
-
return
|
31
|
-
end
|
32
|
-
unless File.exist?(args[0])
|
33
|
-
puts "Man, you gotta give me a valid file to read from!"
|
34
|
-
return
|
35
|
-
end
|
36
|
-
true
|
7
|
+
def convert json
|
8
|
+
TableFormator.new.convert json
|
37
9
|
end
|
38
10
|
|
39
11
|
end
|
@@ -6,12 +6,10 @@ module Tabelr
|
|
6
6
|
@line = []
|
7
7
|
end
|
8
8
|
|
9
|
-
def
|
10
|
-
raise 'aw' if output.respond_to? :Append
|
11
|
-
|
9
|
+
def convert json
|
12
10
|
parse json
|
13
11
|
analyse
|
14
|
-
dump
|
12
|
+
dump
|
15
13
|
end
|
16
14
|
|
17
15
|
def stash data
|
@@ -51,7 +49,8 @@ module Tabelr
|
|
51
49
|
end
|
52
50
|
end
|
53
51
|
|
54
|
-
def dump
|
52
|
+
def dump
|
53
|
+
output = ""
|
55
54
|
output << divider
|
56
55
|
@lines.each_with_index do |line, index|
|
57
56
|
output << divider if index == 1
|
data/tabelr.gemspec
CHANGED
@@ -2,7 +2,7 @@ Gem::Specification.new do |s|
|
|
2
2
|
s.name = "tabelr"
|
3
3
|
s.summary = "Creates neat aligned ascii tables from a json input"
|
4
4
|
s.description = "Creates neat aligned ascii tables from a json input"
|
5
|
-
s.version = "0.0.
|
5
|
+
s.version = "0.0.8"
|
6
6
|
s.author = "Ian Vaughan"
|
7
7
|
s.email = "tabelr@ianvaughan.co.uk"
|
8
8
|
s.homepage = "http://ianvaughan.co.uk"
|
data/test/code_use.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require './lib/tabelr'
|
2
|
+
|
3
|
+
data = {
|
4
|
+
"data" =>
|
5
|
+
[
|
6
|
+
{
|
7
|
+
"column1" => "This",
|
8
|
+
"column2" => "is",
|
9
|
+
"column3" => "quite",
|
10
|
+
"column4" => "cool!"
|
11
|
+
},
|
12
|
+
{
|
13
|
+
"column1" => "This",
|
14
|
+
"column2" => "is the longest field",
|
15
|
+
"column3" => "by far",
|
16
|
+
"column4" => 1241
|
17
|
+
},
|
18
|
+
{
|
19
|
+
"column1" => "Short",
|
20
|
+
"column2" => "fields",
|
21
|
+
"column3" => "fit",
|
22
|
+
"column4" => "in"
|
23
|
+
},
|
24
|
+
{
|
25
|
+
"column1" => "other",
|
26
|
+
"column2" => "eg",
|
27
|
+
"column3" => nil,
|
28
|
+
"column4" => 3322119999999999
|
29
|
+
}
|
30
|
+
]
|
31
|
+
}
|
32
|
+
|
33
|
+
res = Tabelr::convert data
|
34
|
+
puts res.class, res
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tabelr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-08-07 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Creates neat aligned ascii tables from a json input
|
15
15
|
email: tabelr@ianvaughan.co.uk
|
@@ -24,6 +24,7 @@ files:
|
|
24
24
|
- README.md
|
25
25
|
- stash
|
26
26
|
- tabelr.gemspec
|
27
|
+
- test/code_use.rb
|
27
28
|
- test/example.json
|
28
29
|
- test/example.txt
|
29
30
|
- test/example2.json
|
@@ -51,7 +52,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
51
52
|
version: '0'
|
52
53
|
requirements: []
|
53
54
|
rubyforge_project:
|
54
|
-
rubygems_version: 1.8.
|
55
|
+
rubygems_version: 1.8.24
|
55
56
|
signing_key:
|
56
57
|
specification_version: 3
|
57
58
|
summary: Creates neat aligned ascii tables from a json input
|