everyday-cli-utils 1.8.7.1 → 1.8.7.2

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
- SHA1:
3
- metadata.gz: e108393ed60d47c7d3694f022f4c1fc6b846a13e
4
- data.tar.gz: b3f96c931eaa739e99d780079cd6db679f4ff74b
2
+ SHA256:
3
+ metadata.gz: ca7bef9b73263ea19216f8772976432428c2d3c95149515d788e85ae96e16e2b
4
+ data.tar.gz: ae02ca9bbc51dd7d0f096402ae8212ab36142edefce8dd382410c92b8440a716
5
5
  SHA512:
6
- metadata.gz: ac1cada0d96cfd60d3fe8cf13ac9aa710a578569a4b89596d8a93ad5bffefa52d0a0f2d3523522632240b7cac8c9a14a5f036307bec423fda03470990e69fb30
7
- data.tar.gz: 09b46875f35d744b000be73ba63d7692ccfaa352e1c8af54ce2113d66f0c8d056ecc07da32817be6bc420ea412002ed4b0bd39b5e8d07ebbf8f84a27f560e199
6
+ metadata.gz: b480868b9c8cc442f2011cdf89fc16f71f32e6ce97b89174b6c3de82faf8642d32ae28feb30c02b6721ed5f8ad672eb910dd1035e0cd70abc73f925b978de453
7
+ data.tar.gz: a4267353f95609caa80f6e89bc0038365b6eb429e4510b249d99e17d7ab82f0023b1a63d36f24d4d1c8b68d4ee807c6d53c521b2f3fc2cf6cdd10f6c31984fff
@@ -1,2 +1,8 @@
1
1
  language: ruby
2
- gemfile: Gemfile.ci
2
+ gemfile: Gemfile.ci
3
+ addons:
4
+ code_climate:
5
+ repo_token: 9c7db3420cd3e03bfdecf3768a39759d6047ca1a1222cc14d57c9a63803eaa35
6
+ # regular test configuration
7
+ after_success:
8
+ - bundle exec codeclimate-test-reporter
@@ -1,45 +1,45 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- everyday-cli-utils (1.8.6)
4
+ everyday-cli-utils (1.8.7.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- codeclimate-test-reporter (0.5.0)
9
+ codeclimate-test-reporter (0.6.0)
10
10
  simplecov (>= 0.7.1, < 1.0.0)
11
- diff-lcs (1.2.5)
12
- docile (1.1.5)
13
- json (1.8.3)
14
- rake (10.5.0)
15
- rspec (3.4.0)
16
- rspec-core (~> 3.4.0)
17
- rspec-expectations (~> 3.4.0)
18
- rspec-mocks (~> 3.4.0)
19
- rspec-core (3.4.3)
20
- rspec-support (~> 3.4.0)
21
- rspec-expectations (3.4.0)
11
+ diff-lcs (1.3)
12
+ docile (1.3.2)
13
+ json (2.2.0)
14
+ rake (12.3.3)
15
+ rspec (3.8.0)
16
+ rspec-core (~> 3.8.0)
17
+ rspec-expectations (~> 3.8.0)
18
+ rspec-mocks (~> 3.8.0)
19
+ rspec-core (3.8.2)
20
+ rspec-support (~> 3.8.0)
21
+ rspec-expectations (3.8.4)
22
22
  diff-lcs (>= 1.2.0, < 2.0)
23
- rspec-support (~> 3.4.0)
24
- rspec-mocks (3.4.1)
23
+ rspec-support (~> 3.8.0)
24
+ rspec-mocks (3.8.1)
25
25
  diff-lcs (>= 1.2.0, < 2.0)
26
- rspec-support (~> 3.4.0)
27
- rspec-support (3.4.1)
28
- simplecov (0.11.2)
29
- docile (~> 1.1.0)
30
- json (~> 1.8)
26
+ rspec-support (~> 3.8.0)
27
+ rspec-support (3.8.2)
28
+ simplecov (0.17.0)
29
+ docile (~> 1.1)
30
+ json (>= 1.8, < 3)
31
31
  simplecov-html (~> 0.10.0)
32
- simplecov-html (0.10.0)
32
+ simplecov-html (0.10.2)
33
33
 
34
34
  PLATFORMS
35
35
  ruby
36
36
 
37
37
  DEPENDENCIES
38
- bundler (~> 1.10)
38
+ bundler (~> 2.0)
39
39
  codeclimate-test-reporter (~> 0.4, >= 0.4.7)
40
40
  everyday-cli-utils!
41
- rake (~> 10.4)
42
- rspec (~> 3.3)
41
+ rake (~> 12.3)
42
+ rspec (~> 3.8)
43
43
 
44
44
  BUNDLED WITH
45
- 1.11.2
45
+ 2.0.2
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.required_ruby_version = '>= 1.9.3'
22
22
 
23
- spec.add_development_dependency 'bundler', '~> 1.10'
24
- spec.add_development_dependency 'rake', '~> 10.4'
25
- spec.add_development_dependency 'rspec', '~> 3.3'
23
+ spec.add_development_dependency 'bundler', '~> 2.0'
24
+ spec.add_development_dependency 'rake', '~> 12.3'
25
+ spec.add_development_dependency 'rspec', '~> 3.8'
26
26
  end
@@ -9,7 +9,7 @@ module Enumerable
9
9
  EverydayCliUtils::MapUtil.filtermap(self, &block)
10
10
  end
11
11
 
12
- def sum
12
+ def epg_sum
13
13
  EverydayCliUtils::MapUtil.sum(self)
14
14
  end
15
15
 
@@ -416,14 +416,17 @@ module EverydayCliUtils
416
416
  end
417
417
 
418
418
  def opts
419
+ @options ||= OptionList.new
419
420
  @options.opts
420
421
  end
421
422
 
422
423
  def options
424
+ @options ||= OptionList.new
423
425
  @options.composite(:global, :local, :arg)
424
426
  end
425
427
 
426
428
  def option_list
429
+ @options ||= OptionList.new
427
430
  @options
428
431
  end
429
432
 
@@ -438,6 +441,7 @@ module EverydayCliUtils
438
441
  end
439
442
 
440
443
  def help_str=(str)
444
+ @options ||= OptionList.new
441
445
  @options.help_str = str
442
446
  end
443
447
 
@@ -94,6 +94,10 @@ class Object
94
94
  MethodOverrides.register_override(s, self, method_name, &block)
95
95
  end
96
96
 
97
+ def has_override?(method_name)
98
+ !self.true_overrides.empty?(method_name)
99
+ end
100
+
97
101
  class << self
98
102
  def class_overrides(s)
99
103
  @overrides && @overrides.get(s)
@@ -110,5 +114,9 @@ class Object
110
114
  def override(method_name, &block)
111
115
  MethodOverrides.register_override(self, self, method_name, &block)
112
116
  end
117
+
118
+ def has_override?(method_name)
119
+ !self.true_overrides.empty?(method_name)
120
+ end
113
121
  end
114
122
  end
@@ -111,7 +111,7 @@ module EverydayCliUtils
111
111
  kso = ks
112
112
  clusters = EverydayCliUtils::KmeansUtil.get_clusters(collection, kso)
113
113
  ks = []
114
- clusters.each_with_index { |val, key| ks[key] = (val.count <= 0) ? false : (val.sum / val.count) }
114
+ clusters.each_with_index { |val, key| ks[key] = (val.count <= 0) ? false : (EverydayCliUtils::MapUtil.sum(val) / val.count) }
115
115
  min = collection.min
116
116
  max = collection.max
117
117
  ks = ks.map { |k| k || ((Random.rand * (max-min)) + min) }
@@ -149,5 +149,9 @@ module EverydayCliUtils
149
149
  ks.each_with_index { |avg, i| outliers += EverydayCliUtils::KmeansUtil.find_outliers(avg, cs, i, sensitivity) }
150
150
  outliers
151
151
  end
152
+
153
+ def self.get_clusters(collection, means)
154
+ EverydayCliUtils::KmeansUtil.get_clusters(collection, means)
155
+ end
152
156
  end
153
157
  end
@@ -1,3 +1,3 @@
1
1
  module EverydayCliUtils
2
- VERSION = '1.8.7.1'
2
+ VERSION = '1.8.7.2'
3
3
  end
@@ -0,0 +1,7 @@
1
+ require_relative '../../lib/everyday-cli-utils'
2
+
3
+ describe 'everyday-cli-utils' do
4
+ it 'raises an exception when an unknown module name is passed to import' do
5
+ expect { EverydayCliUtils.import(:unknown_module) }.to raise_exception('unknown_module not found!')
6
+ end
7
+ end
@@ -2,25 +2,67 @@ require_relative '../../lib/everyday-cli-utils'
2
2
  include EverydayCliUtils
3
3
  import :kmeans
4
4
 
5
+ def gen_arr(options = {}, &block)
6
+ min = options[:min] || 1
7
+ max = options[:max] || 4
8
+ base_mult = options[:base_mult] || 100
9
+ min2 = options[:min2] || min
10
+ max2 = options[:max2] || max
11
+ (min..max).to_a.flat_map { |v| (min2..max2).to_a.flat_map { |v2| [base_mult*v + block.call(v, v2), 100*v - block.call(v, v2)]}}
12
+ end
13
+
14
+ def expect_arr(actual_to_expected = {})
15
+ actual_to_expected.each { |a, e|
16
+ a = a.sort
17
+ e = e.sort
18
+ expect(a.count).to eq e.count
19
+ expect(a).to eq e
20
+ }
21
+ end
22
+
23
+ def expect_arr_two_deep(actual_to_expected = {})
24
+ actual_to_expected.each { |a, e|
25
+ a = a.sort
26
+ e = e.sort
27
+ expect(a.count).to eq e.count
28
+ (0...a.count).each { |i|
29
+ ai = a[i].sort
30
+ ei = e[i].sort
31
+ expect(ai).to eq ei
32
+ }
33
+ }
34
+ end
35
+
36
+ def expect_arr_count(actual_to_expected_count = {})
37
+ actual_to_expected_count.each { |a, ec|
38
+ expect(a.count).to eq ec
39
+ }
40
+ end
41
+
5
42
  describe EverydayCliUtils::Kmeans do
6
43
  it 'finds the right clusters in simple data' do
7
- arr = [100, 200, 99, 400, 98, 201, 101, 405, 102]
8
- nmeans = arr.nmeans
9
- expect(nmeans.count).to eq 3
10
- expect(nmeans).to eq [100, 200.5, 402.5]
44
+ arr = gen_arr { |v, v2| Math.sqrt(v2) }
45
+ expect_arr arr.nmeans => [100, 200, 300, 400]
11
46
  end
12
47
 
13
48
  it 'limits number of clusters found' do
14
49
  arr = (1..50).to_a.map { |v| (v * (101-v)) ** 2 }
15
- nmeans = arr.nmeans(5)
16
- expect(nmeans.count).to eq 5
17
- nmeans = arr.nmeans(3)
18
- expect(nmeans.count).to eq 3
50
+ expect_arr_count arr.nmeans(5) => 5, arr.nmeans(3) => 3
19
51
  end
20
52
 
21
53
  it 'finds outliers in simple data' do
22
- arr = [100, 200, 99, 400, 98, 201, 101, 405, 102]
23
- outliers = arr.outliers
24
- expect(outliers).to eq [400.0, 405.0]
54
+ arr = gen_arr { |v, v2| (v2+v)/v2 }
55
+ expect_arr arr.outliers => [197, 203, 296, 304, 395, 405]
56
+ end
57
+
58
+ it 'finds the correct means when k is specified' do
59
+ arr = gen_arr { |v, v2| (v2+v)/v2 }
60
+ expect_arr arr.kmeans(2) => [150, 350]
61
+ end
62
+
63
+ it 'finds the correct means when k is specified' do
64
+ arr = gen_arr { |v, v2| (v2+v)/v2 }
65
+ kmeans = arr.kmeans(2)
66
+ expect_arr_two_deep arr.get_clusters(kmeans) => [gen_arr(min: 1, max: 2, min2: 1, max2: 4) { |v, v2| (v2+v)/v2 }, gen_arr(min: 3, max: 4, min2: 1, max2: 4) { |v, v2| (v2+v)/v2 }]
25
67
  end
26
68
  end
@@ -16,7 +16,7 @@ describe 'maputil' do
16
16
 
17
17
  it 'provides a shortcut for summing the values of an list' do
18
18
  arr = (0..9).to_a
19
- sum = arr.sum
19
+ sum = arr.epg_sum
20
20
  expect(sum).to eq 45
21
21
  end
22
22
 
@@ -89,4 +89,12 @@ describe 'maputil' do
89
89
  expected = { a: 11, b: 2, c: 3, d: 14, e: 5, f: 16 }
90
90
  expect(extended).to eq expected
91
91
  end
92
+
93
+ it 'provides a means of subtracting one hash from another' do
94
+ hash1 = { a: 1, b: 2, c: 3, d: 4, e: 5, f: 6 }
95
+ hash2 = { a: 1, d: 14, f: 6 }
96
+ diff = hash1 - hash2
97
+ expected = { b: 2, c: 3, d: 4, e: 5 }
98
+ expect(diff).to eq expected
99
+ end
92
100
  end
@@ -182,6 +182,8 @@ describe EverydayCliUtils::OptionUtil do
182
182
  -0, --set-defaults set defaults
183
183
  '
184
184
  expect(opt.to_s).to eq expected
185
+ opt.help_str = "#{expected}\nTest"
186
+ expect(opt.help).to eq "#{expected}\nTest"
185
187
  end
186
188
 
187
189
  it 'supports layers' do
@@ -195,6 +197,7 @@ describe EverydayCliUtils::OptionUtil do
195
197
  clean = { opt1: false, opt2: [], opt3: nil, opt4: [] }
196
198
  clean2 = { opt1: true, opt2: [], opt3: nil, opt4: [] }
197
199
  opt = Option1.new
200
+ expect(opt.opts).to be_a(OptionParser)
198
201
  opt.default_settings toggle: true, append: true
199
202
  opt.option :opt1, %w(-1 --opt-1)
200
203
  opt.option_with_param :opt2, %w(-2 --big-opt-2)
@@ -255,13 +258,63 @@ Script + Global + Local Defaults:
255
258
 
256
259
  SHOW
257
260
  opt.apply_options :arg, opt1: true
258
- expect(opt.options).to eq total
259
- expect(opt.option_list.composite(:global, :arg)).to eq global_arg
260
- expect(opt.option_list.composite(:global, :local)).to eq global_local
261
- expect(opt.option_list.composite(:global)).to eq global
262
- expect(opt.option_list.composite(:local)).to eq local
263
- expect(opt.option_list.composite(:local, :arg)).to eq local_arg
264
- expect(opt.option_list.composite(:arg)).to eq arg
265
- expect(opt.option_list.composite(:global, :local, :arg)).to eq total
261
+ opt.show_defaults_option %w(-d --show-defaults), exit_on_show: false
262
+ file = File.expand_path('global_defaults.yaml')
263
+ begin
264
+ opt.global_defaults_option file, %w(-g --global-defaults), exit_on_save: true
265
+ opt.help_option %w(-h --help), exit_on_print: false
266
+ expect(opt.options).to eq total
267
+ expect(opt.option_list.composite(:global, :arg)).to eq global_arg
268
+ expect(opt.option_list.composite(:global, :local)).to eq global_local
269
+ expect(opt.option_list.composite(:global)).to eq global
270
+ expect(opt.option_list.composite(:local)).to eq local
271
+ expect(opt.option_list.composite(:local, :arg)).to eq local_arg
272
+ expect(opt.option_list.composite(:arg)).to eq arg
273
+ expect(opt.option_list.composite(:global, :local, :arg)).to eq total
274
+ $stdout = StringIO.new
275
+ opt.parse!(%w(-h -d))
276
+ expect($stdout.string).to eq 'Usage: rspec [options]
277
+ -1, --opt-1
278
+ -2, --big-opt-2 PARAM
279
+ -3, --bigger-opt-3 PARAM
280
+ -4, --even-bigger-opt-4 PARAM
281
+ -d, --show-defaults
282
+ -g, --global-defaults
283
+ -h, --help
284
+ Script Defaults:
285
+ -1, --opt-1 true
286
+ -2 PARAM, --big-opt-2 []
287
+ -3 PARAM, --bigger-opt-3 nil
288
+ -4 PARAM, --even-bigger-opt-4 []
289
+
290
+ Script + Global Defaults:
291
+ -1, --opt-1 false
292
+ -3 PARAM, --bigger-opt-3 \'hi\'
293
+ -4 PARAM, --even-bigger-opt-4 [5]
294
+
295
+ Script + Global + Local Defaults:
296
+ -2 PARAM, --big-opt-2 [\'hi\', \'bye\']
297
+ -3 PARAM, --bigger-opt-3 \'bye\'
298
+ -4 PARAM, --even-bigger-opt-4 [5, 4]
299
+
300
+ '
301
+ expect { opt.parse!(%w(-g)) }.to raise_exception(SystemExit)
302
+ ensure
303
+ File.delete(file)
304
+ end
305
+ end
306
+
307
+ it 'still supports the old option style' do
308
+ vals = {value: '', multi: [], toggle: true}
309
+ opts = OptionParser.new { |opts|
310
+ EverydayCliUtils::Option.add_option_with_param(vals, opts, ['-v', '--value PARAM'], :value)
311
+ EverydayCliUtils::Option.add_option_with_param(vals, opts, ['-m', '--multi PARAM'], :multi, append: true)
312
+ EverydayCliUtils::Option.add_option(vals, opts, %w(-t --toggle), :toggle, toggle: true)
313
+ }
314
+ expected = {value: '', multi: [], toggle: true}
315
+ expect(vals).to eq expected
316
+ opts.parse!(%w(-v ABC -m DEF -m GHI -t))
317
+ expected = {value: 'ABC', multi: ['DEF', 'GHI'], toggle: false}
318
+ expect(vals).to eq expected
266
319
  end
267
320
  end
@@ -20,6 +20,8 @@ describe 'override' do
20
20
  arr.override(:first) { "Boo! #{self.overrides.first}" }
21
21
  arr.override(:first) { "Boo Again! #{self.overrides[1].first}" }
22
22
  arr.override(:first) { "Boo Again Again! #{self.overrides[1].first} | #{self.overrides.first}" }
23
+ expect(arr.has_override?(:first)).to be true
24
+ expect(arr.has_override?(:test)).to be false
23
25
  expect(arr.first).to eq 'Boo Again Again! Boo! 1 | Boo Again! 1'
24
26
  end
25
27
 
@@ -27,6 +29,8 @@ describe 'override' do
27
29
  TestClass.override(:test) { |t| "Boo! #{self.overrides.test("-#{t}-")}" }
28
30
  TestClass.override(:test) { |t| "Boo Again! #{self.overrides[1].test("+#{t}+")}" }
29
31
  TestClass.override(:test) { |t| "Boo Again Again! #{self.overrides[1].test("!#{t}!")} | #{self.overrides.test("~#{t}~")}" }
32
+ expect(TestClass.has_override?(:first)).to be false
33
+ expect(TestClass.has_override?(:test)).to be true
30
34
  expect(TestClass.new.test('Eric')).to eq 'Boo Again Again! Boo! Hi -!Eric!-! | Boo Again! Hi +~Eric~+!'
31
35
  end
32
36
 
@@ -1,2 +1,2 @@
1
- require 'codeclimate-test-reporter'
2
- CodeClimate::TestReporter.start
1
+ require 'simplecov'
2
+ SimpleCov.start
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: everyday-cli-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.7.1
4
+ version: 1.8.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Henderson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-09 00:00:00.000000000 Z
11
+ date: 2019-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,42 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.10'
19
+ version: '2.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.10'
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.4'
33
+ version: '12.3'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.4'
40
+ version: '12.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '3.3'
47
+ version: '3.8'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '3.3'
54
+ version: '3.8'
55
55
  description: A few CLI and general utilities. Includes a numbered-menu select loop
56
56
  utility, a ANSI formatting escape code handler, a text-based histogram maker, k-means
57
57
  and n-means (k-means with minimum optimal k) calculators, various collection utility
@@ -85,6 +85,7 @@ files:
85
85
  - lib/everyday-cli-utils/safe/kmeans.rb
86
86
  - lib/everyday-cli-utils/safe/maputil.rb
87
87
  - lib/everyday-cli-utils/version.rb
88
+ - spec/everyday-cli-utils/base_spec.rb
88
89
  - spec/everyday-cli-utils/format_spec.rb
89
90
  - spec/everyday-cli-utils/kmeans_spec.rb
90
91
  - spec/everyday-cli-utils/maputil_spec.rb
@@ -110,16 +111,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
111
  - !ruby/object:Gem::Version
111
112
  version: '0'
112
113
  requirements: []
113
- rubyforge_project:
114
- rubygems_version: 2.5.1
114
+ rubygems_version: 3.0.4
115
115
  signing_key:
116
116
  specification_version: 4
117
117
  summary: A few CLI and general utils
118
118
  test_files:
119
+ - spec/everyday-cli-utils/base_spec.rb
119
120
  - spec/everyday-cli-utils/format_spec.rb
120
121
  - spec/everyday-cli-utils/kmeans_spec.rb
121
122
  - spec/everyday-cli-utils/maputil_spec.rb
122
123
  - spec/everyday-cli-utils/option_spec.rb
123
124
  - spec/everyday-cli-utils/override_spec.rb
124
125
  - spec/spec_helper.rb
125
- has_rdoc: