ix-cli 0.0.21 → 0.0.22

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 310ce8e1c17438e6004dd28f1dfe8f4f9501c5c7ecbca7d5efa75c4c5095e290
4
- data.tar.gz: 8ac9335f579d2ffbfb5549409308de3250e173c35688f130d5719d2b421acd0d
3
+ metadata.gz: e6201f592feb8666f1617290e1475d0c2c2763f3d9e9fffdc6fe22b764c54602
4
+ data.tar.gz: 351cd99558c3e85c47599dea7bb938d6c19c07b1a39eedcd079549772ba53b26
5
5
  SHA512:
6
- metadata.gz: 4cbf17184a8274e7579e8cbb660f972890f533421840ca0f43c2e7a2538249f5f8f022b766e464b0130ee5735629f1522ea15c0257cfdadaef2f4906cfe5d105
7
- data.tar.gz: e5ed936aec0c930d755ff5d267425aaa01473f1220bbf9e2d9424b265e354566de834a0bb967f4e90982e2c7c78bb9e01610fe64fb0d87da81db1d8fc50ee15f
6
+ metadata.gz: 59aaabd4241f214b5f95152b69075cf78cb6b6f7c57c3a2a44960cd245d3343f240078c341a11143716e401b33fccdcc4640b708190b3be419410fcf641a6548
7
+ data.tar.gz: ea63c41c3955f956af5df4122a1e93d0853ce6e4eff83aa90050addbad2f67497163f0872c45b1805ff20ffe9daf3b9aac23bec2e519f32c1e03b37f6624c4f9
data/bin/ix-json-to-table CHANGED
@@ -6,6 +6,8 @@ require 'optparse'
6
6
 
7
7
  options = {}
8
8
  options[:orient] = 'top'
9
+ options[:transpose] = false
10
+ options[:adjust] = false
9
11
 
10
12
  OptionParser.new do |opts|
11
13
 
@@ -19,6 +21,14 @@ OptionParser.new do |opts|
19
21
  options[:search] = Regexp.new(value, Regexp::IGNORECASE)
20
22
  end
21
23
 
24
+ opts.on('-t', '--transpose', 'Transponse the table and print the output vertically.') do |value|
25
+ options[:transpose] = value
26
+ end
27
+
28
+ opts.on('-a', '--adjust', 'Adjust width of tables when in transpose mode.') do |value|
29
+ options[:adjust] = value
30
+ end
31
+
22
32
  end.parse!
23
33
 
24
34
  required_options = [:orient]
@@ -29,14 +39,6 @@ required_options.each do |option|
29
39
  end
30
40
  end
31
41
 
32
- data = []
33
-
34
- STDIN.each_line do |line|
35
- data << JSON.parse(line)
36
- end
37
-
38
- exit if data.empty?
39
-
40
42
  def print_table(data, options)
41
43
  columns = {}
42
44
 
@@ -104,4 +106,64 @@ def print_table(data, options)
104
106
  puts "Total: #{data.size} rows"
105
107
  end
106
108
 
107
- print_table(data, options)
109
+ def transpose(hash)
110
+ transposed = {}
111
+ hash.each do |key, value|
112
+ transposed[key] ||= []
113
+ transposed[key] << value
114
+ end
115
+ transposed
116
+ end
117
+
118
+ if options[:transpose]
119
+
120
+ data = []
121
+
122
+ STDIN.each_line do |line|
123
+ begin
124
+ data << JSON.parse(line)
125
+ rescue => e
126
+ $stderr.puts e.message
127
+ end
128
+ end
129
+
130
+ max_length = 0
131
+
132
+ if options[:adjust]
133
+ data.each do |object|
134
+ object.values.each do |value|
135
+ max_length = value.to_s.size if value.to_s.size > max_length
136
+ end
137
+ end
138
+ end
139
+
140
+ data.each do |object|
141
+ transposed = transpose(object)
142
+ new_data = []
143
+ transposed.each do |key, values|
144
+ values.each do |value|
145
+ new_data.push({ 'column' => key, 'value' => value.to_s.ljust(max_length, ' ')})
146
+ end
147
+ end
148
+ puts ''
149
+ print_table(new_data, options)
150
+ end
151
+
152
+ else
153
+
154
+ data = []
155
+
156
+ STDIN.each_line do |line|
157
+ begin
158
+ data << JSON.parse(line)
159
+ rescue => e
160
+ $stderr.puts e.message
161
+ end
162
+ end
163
+
164
+ exit if data.empty?
165
+
166
+ print_table(data, options)
167
+
168
+ end
169
+
@@ -2,19 +2,22 @@
2
2
 
3
3
  require 'json'
4
4
 
5
- transposed = {}
6
-
7
- STDIN.each_line do |line|
8
- data = JSON.parse(line)
9
- data.each do |key, value|
5
+ def transpose(hash)
6
+ transposed = {}
7
+ hash.each do |key, value|
10
8
  transposed[key] ||= []
11
9
  transposed[key] << value
12
10
  end
11
+ transposed
13
12
  end
14
13
 
15
- transposed.each do |key, values|
16
- values.each do |value|
17
- puts({ :column => key, :value => value }.to_json)
14
+ STDIN.each_line do |line|
15
+ data = JSON.parse(line)
16
+ transposed = transpose(data)
17
+ transposed.each do |key, values|
18
+ values.each do |value|
19
+ puts({ :column => key, :value => value }.to_json)
20
+ end
18
21
  end
19
22
  end
20
23
 
data/bin/ix-remove CHANGED
@@ -9,13 +9,13 @@ OptionParser.new do |opts|
9
9
 
10
10
  opts.banner = "Usage: #{$0} [OPTIONS]"
11
11
 
12
- opts.on('-f', '--file []', 'File with entries to be removed.') do |value|
13
- options[:file] = value
12
+ opts.on('-r', '--remove [FILEPATH]', 'File with entries that will be removed.') do |value|
13
+ options[:remove] = value
14
14
  end
15
15
 
16
16
  end.parse!
17
17
 
18
- required_options = [:file]
18
+ required_options = [:remove]
19
19
  required_options.each do |option|
20
20
  unless options[option]
21
21
  $stderr.puts "Can not run #{option.to_s} was not given."
@@ -23,24 +23,24 @@ required_options.each do |option|
23
23
  end
24
24
  end
25
25
 
26
- unless File.exist?(options[:file])
27
- $stderr.puts "File #{options[:file]} does not exist."
26
+ unless File.exist?(options[:remove])
27
+ $stderr.puts "File #{options[:remove]} does not exist."
28
28
  exit 1
29
29
  end
30
30
 
31
- inputs = []
32
- entries = []
31
+ source_list = []
32
+ remove_list = []
33
33
 
34
34
 
35
- File.read(options[:file]).each_line do |line|
36
- entries << line
35
+ File.read(options[:remove]).each_line do |line|
36
+ remove_list << line.chomp
37
37
  end
38
38
 
39
39
  STDIN.each_line do |line|
40
- inputs << line
40
+ source_list << line.chomp
41
41
  end
42
42
 
43
- (inputs - entries).each do |item|
44
- puts item.chomp
43
+ (source_list - remove_list).each do |item|
44
+ puts item
45
45
  end
46
46
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ix-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.21
4
+ version: 0.0.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kazuyoshi Tlacaelel
@@ -287,7 +287,6 @@ executables:
287
287
  - ix-symlink
288
288
  - ix-tab
289
289
  - ix-tabify
290
- - ix-table
291
290
  - ix-tac
292
291
  - ix-task
293
292
  - ix-technical
@@ -594,7 +593,6 @@ files:
594
593
  - bin/ix-symlink
595
594
  - bin/ix-tab
596
595
  - bin/ix-tabify
597
- - bin/ix-table
598
596
  - bin/ix-tac
599
597
  - bin/ix-task
600
598
  - bin/ix-technical
data/bin/ix-table DELETED
@@ -1,22 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'optparse'
4
-
5
- options = {}
6
-
7
- OptionParser.new do |opts|
8
-
9
- opts.banner = "Usage: #{$0} [OPTIONS]"
10
-
11
- opts.on('-v', '--vertical', 'Vertical.') do |value|
12
- options[:vertical] = value
13
- end
14
-
15
- end.parse!
16
-
17
- if options[:vertical]
18
- system 'ruby ./ix-json-transpose | ruby ./ix-json-to-table'
19
- else
20
- system 'ruby ./ix-json-to-table'
21
- end
22
-