vj 1.0.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8650414a22b2447752eda609dcf1f5b342066151
4
+ data.tar.gz: b1bc95966768b174d11b61e1351e7feeae0dd8c0
5
+ SHA512:
6
+ metadata.gz: 7c2d06e832de552f1aa0aa1352cd2e0bc64475174fc7c290278c8de8a10c21d5023e488b3126ad53fd69fbbefbb6e34ee151a620e96bd0f841212e5ba2db0319
7
+ data.tar.gz: 5e1b352bf63c7fbbbc90d399a36c8e4e84cfcf78b33b5a16beb0b0976f99cfb75b589c04b8e7f2c1d4ffe68bff5ee81b1ff0e6487c67452eb505dc6a0215c379
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.rubocop.yml ADDED
@@ -0,0 +1,52 @@
1
+ # Offense count: 1
2
+ Metrics/AbcSize:
3
+ Max: 120
4
+
5
+ # Offense count: 1
6
+ # Configuration parameters: CountComments, ExcludedMethods.
7
+ Metrics/BlockLength:
8
+ Max: 42
9
+
10
+ # Offense count: 1
11
+ Metrics/CyclomaticComplexity:
12
+ Max: 42
13
+
14
+ # Offense count: 1
15
+ # Configuration parameters: CountComments.
16
+ Metrics/MethodLength:
17
+ Max: 100
18
+
19
+ # Offense count: 1
20
+ Metrics/PerceivedComplexity:
21
+ Max: 42
22
+
23
+ # Offense count: 1
24
+ Security/Eval:
25
+ Exclude:
26
+ - 'lib/vj.rb'
27
+
28
+ # Offense count: 1
29
+ Style/Documentation:
30
+ Exclude:
31
+ - 'spec/**/*'
32
+ - 'test/**/*'
33
+ - 'lib/vj.rb'
34
+
35
+ # Offense count: 7
36
+ # Configuration parameters: EnforcedStyle.
37
+ # SupportedStyles: annotated, template, unannotated
38
+ Style/FormatStringToken:
39
+ Exclude:
40
+ - 'lib/vj.rb'
41
+
42
+ # Offense count: 2
43
+ # Configuration parameters: AllowedVariables.
44
+ Style/GlobalVars:
45
+ Exclude:
46
+ - 'lib/vj.rb'
47
+
48
+ # Offense count: 5
49
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
50
+ # URISchemes: http, https
51
+ Metrics/LineLength:
52
+ Max: 200
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in vj.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,51 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ vj (1.0.0)
5
+ oj
6
+ optix
7
+ paint
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ ast (2.3.0)
13
+ bump (0.5.3)
14
+ bundler-audit (0.6.0)
15
+ bundler (~> 1.2)
16
+ thor (~> 0.18)
17
+ chronic (0.10.2)
18
+ oj (3.3.9)
19
+ optix (1.2.5)
20
+ chronic
21
+ paint (2.0.1)
22
+ parallel (1.12.1)
23
+ parser (2.4.0.2)
24
+ ast (~> 2.3)
25
+ powerpack (0.1.1)
26
+ rainbow (3.0.0)
27
+ rake (10.5.0)
28
+ rubocop (0.52.0)
29
+ parallel (~> 1.10)
30
+ parser (>= 2.4.0.2, < 3.0)
31
+ powerpack (~> 0.1)
32
+ rainbow (>= 2.2.2, < 4.0)
33
+ ruby-progressbar (~> 1.7)
34
+ unicode-display_width (~> 1.0, >= 1.0.1)
35
+ ruby-progressbar (1.9.0)
36
+ thor (0.20.0)
37
+ unicode-display_width (1.3.0)
38
+
39
+ PLATFORMS
40
+ ruby
41
+
42
+ DEPENDENCIES
43
+ bump
44
+ bundler (~> 1.16)
45
+ bundler-audit
46
+ rake (~> 10.0)
47
+ rubocop
48
+ vj!
49
+
50
+ BUNDLED WITH
51
+ 1.16.0
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2017, moe@busyloop.net
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ 1. Redistributions of source code must retain the above copyright notice, this
8
+ list of conditions and the following disclaimer.
9
+ 2. Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation
11
+ and/or other materials provided with the distribution.
12
+
13
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/Makefile ADDED
@@ -0,0 +1,5 @@
1
+ SHELL=/bin/bash
2
+
3
+ test:
4
+ bundle exec bundle-audit check --update
5
+ bundle exec rubocop
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # ![vj](https://user-images.githubusercontent.com/1622080/34383949-35e614d2-eb19-11e7-808d-5ec2c2bdf3ac.jpg)
2
+
3
+
4
+ ## Installation
5
+
6
+ ```
7
+ gem install vj
8
+ ```
9
+
10
+
11
+
12
+ ## Before
13
+
14
+ `nc api.bitcoincharts.com 27007`
15
+
16
+ ![before](https://user-images.githubusercontent.com/1622080/34383914-f8926158-eb18-11e7-8883-fcb985a48d31.png)
17
+
18
+
19
+
20
+ # ✨ After ✨
21
+
22
+ `nc api.bitcoincharts.com 27007 | vj -c symbol -p price`
23
+
24
+ ![after](https://user-images.githubusercontent.com/1622080/34383934-1ea509ae-eb19-11e7-9c41-6b437d217321.png)
25
+
26
+
27
+
28
+ ## License (BSD)
29
+
30
+ Copyright (c) 2017, moe@busyloop.net
31
+ All rights reserved.
32
+
33
+ Redistribution and use in source and binary forms, with or without
34
+ modification, are permitted provided that the following conditions are met:
35
+
36
+ 1. Redistributions of source code must retain the above copyright notice, this
37
+ list of conditions and the following disclaimer.
38
+ 2. Redistributions in binary form must reproduce the above copyright notice,
39
+ this list of conditions and the following disclaimer in the documentation
40
+ and/or other materials provided with the distribution.
41
+
42
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
43
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
44
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
45
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
46
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
47
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
48
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
49
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
50
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
51
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'test'
6
+ t.libs << 'lib'
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'vj'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/vj ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'vj'
5
+
6
+ Optix.invoke!
data/lib/vj.rb ADDED
@@ -0,0 +1,99 @@
1
+ require 'vj/version'
2
+
3
+ require 'oj'
4
+ require 'optix'
5
+ require 'set'
6
+ require 'digest'
7
+ require 'paint'
8
+
9
+ module Vj
10
+ class Cli < Optix::Cli
11
+ TEMPLATE_OPTS = %i[before_key after_key before_value after_value].freeze
12
+ cli_root do
13
+ text "vj v#{Vj::VERSION}"
14
+ opt :version, 'Print version and exit', short: :none
15
+ trigger :version do
16
+ puts "vj v#{Tc::VERSION}"
17
+ end
18
+ end
19
+
20
+ parent :none
21
+ opt :suppress, 'Suppress keys', type: :strings
22
+ opt :prioritize, 'Prioritize keys', type: :strings
23
+ opt :template, 'Template for JSON lines', short: :t, default: '\e[4m%{key}\e[0m \e[1m%{value}\e[0m '
24
+ opt :nonjson_template, 'Template for conversion of non-JSON lines to JSON', short: :T, default: '{ "E": "%{default_event_id}", "msg": "%{quoted_line}" }'
25
+ opt :color_key, 'Color by key', short: :c, type: :string
26
+ opt :default_event_id, 'Default event id', default: 'container'
27
+ opt :light_background, 'Light terminal background', default: false
28
+ opt :jsonify, 'Output JSON', short: :J
29
+ text 'JSON Humanizer'
30
+ def main(_cmd, opts, _argv)
31
+ if ($stdout.isatty || ENV['FORCE_UNBUFFERED']) && ENV['FORCE_BUFFERED'].nil?
32
+ $stdout.sync = true
33
+ $stdin.sync = true
34
+ end
35
+
36
+ palette = bob_ross(opts[:light_background])
37
+ opts[:prioritize] ||= []
38
+
39
+ base_json = nil
40
+ base_json_line_key = nil
41
+
42
+ begin
43
+ base_json = Oj.load(format(opts[:nonjson_template], default_event_id: opts[:default_event_id], quoted_line: '%{quoted_line}'))
44
+ base_json.each_pair do |k, v|
45
+ if v == '%{quoted_line}'
46
+ base_json_line_key = k
47
+ break
48
+ end
49
+ end
50
+ rescue StandardError => e
51
+ puts "Error: nonjson-template is not valid JSON (#{e})"
52
+ exit 1
53
+ end
54
+ suppress_keys = Set.new(opts[:suppress])
55
+ hash = nil
56
+ STDIN.each do |line|
57
+ line.chomp!
58
+ next if line == ''
59
+ begin
60
+ hash = Oj.load(line)
61
+ next if hash.nil?
62
+ rescue StandardError => e
63
+ hash = Marshal.load(Marshal.dump(base_json))
64
+ hash[base_json_line_key] = line
65
+ end
66
+
67
+ if opts[:jsonify]
68
+ puts Oj.dump(hash)
69
+ next
70
+ end
71
+
72
+ color = nil
73
+ if hash[opts[:color_key]]
74
+ color = palette[Digest::MD5.hexdigest(hash[opts[:color_key]].to_s).to_i(16) % palette.length]
75
+ print Paint[" #{hash[opts[:color_key]]} ", color, :inverse] + ' '
76
+ hash.delete(opts[:color_key])
77
+ end
78
+
79
+ keys = hash.keys.sort
80
+ opts[:prioritize].reverse.each do |pkey|
81
+ keys.unshift(keys.delete(pkey)) if keys.include? pkey
82
+ end
83
+
84
+ keys.each do |k|
85
+ next if suppress_keys.include?(k)
86
+ v = hash[k]
87
+ next if v.nil? || v == ''
88
+ print Paint[eval(format('"%s"', format(opts[:template], key: k, value: v).tr('"', "\001"))).tr("\001", '"'), color]
89
+ end
90
+ puts
91
+ end
92
+ end
93
+
94
+ def bob_ross(light = true)
95
+ op = light ? :reject : :select
96
+ Paint::RGB_COLORS.values.reject { |r, g, b| r == g && g == b }.send(op) { |r, g, b| (((r * 299) + (g * 587) + (b * 114)) / 1000.0 > 127) }
97
+ end
98
+ end
99
+ end
data/lib/vj/version.rb ADDED
@@ -0,0 +1,3 @@
1
+ module Vj
2
+ VERSION = '1.0.0'.freeze
3
+ end
data/vj.gemspec ADDED
@@ -0,0 +1,32 @@
1
+
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vj/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'vj'
8
+ spec.version = Vj::VERSION
9
+ spec.authors = ['moe']
10
+ spec.email = ['moe@busyloop.net']
11
+
12
+ spec.summary = 'JSON humanizer.'
13
+ spec.description = 'JSON humanizer.'
14
+ spec.homepage = 'https://github.com/busyloop/vj'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = 'exe'
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_dependency 'oj'
24
+ spec.add_dependency 'optix'
25
+ spec.add_dependency 'paint'
26
+
27
+ spec.add_development_dependency 'bump'
28
+ spec.add_development_dependency 'bundler', '~> 1.16'
29
+ spec.add_development_dependency 'bundler-audit'
30
+ spec.add_development_dependency 'rake', '~> 10.0'
31
+ spec.add_development_dependency 'rubocop'
32
+ end
metadata ADDED
@@ -0,0 +1,170 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vj
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - moe
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-12-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: oj
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: optix
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: paint
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bump
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.16'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.16'
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler-audit
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '10.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '10.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: JSON humanizer.
126
+ email:
127
+ - moe@busyloop.net
128
+ executables:
129
+ - vj
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - ".gitignore"
134
+ - ".rubocop.yml"
135
+ - Gemfile
136
+ - Gemfile.lock
137
+ - LICENSE
138
+ - Makefile
139
+ - README.md
140
+ - Rakefile
141
+ - bin/console
142
+ - bin/setup
143
+ - exe/vj
144
+ - lib/vj.rb
145
+ - lib/vj/version.rb
146
+ - vj.gemspec
147
+ homepage: https://github.com/busyloop/vj
148
+ licenses: []
149
+ metadata: {}
150
+ post_install_message:
151
+ rdoc_options: []
152
+ require_paths:
153
+ - lib
154
+ required_ruby_version: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ required_rubygems_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ requirements: []
165
+ rubyforge_project:
166
+ rubygems_version: 2.5.2
167
+ signing_key:
168
+ specification_version: 4
169
+ summary: JSON humanizer.
170
+ test_files: []