tabelr 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
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 SQU query output from Sequel Pro app, which can save results as json.
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
- ruby bin/tabelr test/example.json test/output.txt
14
+ Command line :-
15
15
 
16
+ ruby bin/tabelr test/example.json test/output.txt
16
17
 
17
- input
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
- output
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
- Tabelr::run
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
+
@@ -4,36 +4,8 @@ require_relative '../lib/tabelr/table_formater'
4
4
  module Tabelr
5
5
  class << self
6
6
 
7
- def run
8
- args = parse_args
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 go json, output
10
- raise 'aw' if output.respond_to? :Append
11
-
9
+ def convert json
12
10
  parse json
13
11
  analyse
14
- dump output
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 output
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
@@ -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.7"
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"
@@ -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.7
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-05-01 00:00:00.000000000 Z
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.17
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