trick_bag 0.30.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. data/.gitignore +19 -0
  2. data/Gemfile +4 -0
  3. data/Guardfile +8 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +32 -0
  6. data/RELEASE_NOTES.md +3 -0
  7. data/Rakefile +1 -0
  8. data/lib/trick_bag.rb +7 -0
  9. data/lib/trick_bag/collections/linked_list.rb +97 -0
  10. data/lib/trick_bag/enumerables/buffered_enumerable.rb +90 -0
  11. data/lib/trick_bag/enumerables/compound_enumerable.rb +114 -0
  12. data/lib/trick_bag/enumerables/filtered_enumerable.rb +32 -0
  13. data/lib/trick_bag/io/temp_files.rb +22 -0
  14. data/lib/trick_bag/io/text_mode_status_updater.rb +59 -0
  15. data/lib/trick_bag/meta/classes.rb +87 -0
  16. data/lib/trick_bag/numeric/multi_counter.rb +44 -0
  17. data/lib/trick_bag/numeric/totals.rb +49 -0
  18. data/lib/trick_bag/operators/operators.rb +13 -0
  19. data/lib/trick_bag/timing/timing.rb +47 -0
  20. data/lib/trick_bag/validations/hash_validations.rb +21 -0
  21. data/lib/trick_bag/validations/object_validations.rb +26 -0
  22. data/lib/trick_bag/version.rb +3 -0
  23. data/spec/spec_helper.rb +11 -0
  24. data/spec/trick_bag/collections/linked_list_spec.rb +64 -0
  25. data/spec/trick_bag/enumerables/buffered_enumerable_spec.rb +117 -0
  26. data/spec/trick_bag/enumerables/compound_enumerable_spec.rb +141 -0
  27. data/spec/trick_bag/enumerables/filtered_enumerable_spec.rb +35 -0
  28. data/spec/trick_bag/io/temp_files_spec.rb +31 -0
  29. data/spec/trick_bag/io/text_mode_status_updater_spec.rb +24 -0
  30. data/spec/trick_bag/meta/classes_spec.rb +211 -0
  31. data/spec/trick_bag/numeric/multi_counter_spec.rb +28 -0
  32. data/spec/trick_bag/numeric/totals_spec.rb +38 -0
  33. data/spec/trick_bag/operators/operators_spec.rb +33 -0
  34. data/spec/trick_bag/timing/timing_spec.rb +17 -0
  35. data/spec/trick_bag/validations/hashes_validations_spec.rb +39 -0
  36. data/spec/trick_bag/validations/object_validations_spec.rb +23 -0
  37. data/trick_bag.gemspec +28 -0
  38. metadata +194 -0
@@ -0,0 +1,28 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ require 'trick_bag/numeric/multi_counter'
4
+
5
+ module TrickBag
6
+ module Numeric
7
+ describe MultiCounter do
8
+
9
+ subject { MultiCounter.new }
10
+
11
+ it "should instantiate" do
12
+ expect(-> { subject }).not_to raise_error
13
+ end
14
+
15
+ it "should increment a class name and return 1" do
16
+ subject.increment('String')
17
+ expect(subject['String']).to eq(1)
18
+ end
19
+
20
+ it "should provide a list of keys" do
21
+ keys = %w(foo bar baz)
22
+ keys.each { |key| subject.increment(key) }
23
+ expect(subject.keys.sort).to eq(keys.sort)
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,38 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ require 'trick_bag/numeric/totals'
4
+
5
+ module TrickBag
6
+ module Numeric
7
+
8
+ describe Totals do
9
+
10
+ it "calculates correct fraction of total" do
11
+ expect(Totals.map_fraction_of_total([2, 4, 6, 8])).to eq([0.1, 0.2, 0.3, 0.4])
12
+ end
13
+
14
+ it "calculates correct percent of total" do
15
+ expect(Totals.map_percent_of_total([2, 4, 6, 8])).to eq([10, 20, 30, 40])
16
+ end
17
+
18
+ it "returns an empty array when handed an empty array" do
19
+ expect(Totals.map_percent_of_total([])).to eq([])
20
+ expect(Totals.map_fraction_of_total([])).to eq([])
21
+ end
22
+
23
+ it 'produces a correct % of total hash' do
24
+ orig_hash = { foo: 100, bar: 200, baz: 300, razz: 400 }
25
+ percent_hash = Totals.percent_of_total_hash(orig_hash)
26
+ expected_hash = { foo: 10.0, bar: 20.0, baz: 30.0, razz: 40.0 }
27
+ expect(percent_hash).to eq(expected_hash)
28
+ end
29
+
30
+ it 'produces a correct fraction of total hash' do
31
+ orig_hash = { foo: 100, bar: 200, baz: 300, razz: 400 }
32
+ percent_hash = Totals.fraction_of_total_hash(orig_hash)
33
+ expected_hash = { foo: 0.1, bar: 0.2, baz: 0.3, razz: 0.4 }
34
+ expect(percent_hash).to eq(expected_hash)
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,33 @@
1
+ require_relative '../../spec_helper'
2
+ require 'trick_bag/operators/operators'
3
+
4
+ module TrickBag
5
+
6
+ describe Operators do
7
+ context "multi_eq" do
8
+
9
+ specify "that calling with no params raises an error" do
10
+ expect(->{ Operators.multi_eq() }).to raise_error
11
+ end
12
+
13
+ specify "that calling with no params raises an error" do
14
+ expect(->{ Operators.multi_eq(1) }).to raise_error
15
+ end
16
+
17
+ test_for = ->(true_or_false, *values) do
18
+ specify "that #{values.map(&:to_s).join(', ')} returns #{true_or_false}}" do
19
+ expect(Operators.multi_eq(*values)).to eq(true_or_false)
20
+ end
21
+ end
22
+
23
+ test_for.(true, 12, 12)
24
+ test_for.(false, 0, 12)
25
+ test_for.(true, :foo, :foo, :foo)
26
+ test_for.(false, :bar, :foo, :foo)
27
+ test_for.(false, :foo, :bar, :foo)
28
+ test_for.(false, :foo, :foo, :bar)
29
+ test_for.(true, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7)
30
+ test_for.(false, 7, 7, 7, 7, 7, 9999, 7, 7, 7, 7, 7)
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,17 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ require 'trick_bag/timing/timing'
4
+
5
+ module TrickBag
6
+
7
+ describe Timing do
8
+
9
+ it 'returns when the predicate returns true' do
10
+ count = 0
11
+ predicate = ->{ count += 1; count == 3 }
12
+ Timing.retry_until_true_or_timeout(predicate, 0, 1, StringIO.new)
13
+ expect(count).to eq(3)
14
+ end
15
+ end
16
+
17
+ end
@@ -0,0 +1,39 @@
1
+ require_relative '../../spec_helper.rb'
2
+
3
+ require 'trick_bag/validations/hash_validations'
4
+
5
+ module TrickBag
6
+ module Validations
7
+ describe HashValidations do
8
+
9
+ include HashValidations
10
+
11
+ it 'should return a correct list of missing keys' do
12
+ h = { a: 1, c: 1, e: 1}
13
+ keys_to_test = [:e, :d, :c, :b, :a]
14
+ expect(missing_hash_entries(h, keys_to_test)).to eq([:d, :b])
15
+ end
16
+
17
+
18
+ it 'should return an empty array for no missing keys' do
19
+ h = { a: 1, c: 1, e: 1}
20
+ keys_to_test = [:e, :c, :a]
21
+ expect(missing_hash_entries(h, keys_to_test)).to eq([])
22
+ end
23
+
24
+
25
+ it 'should return a correct string listing missing keys' do
26
+ h = { a: 1, c: 1, e: 1}
27
+ keys_to_test = [:e, :d, :c, :b, :a]
28
+ expect(missing_hash_entries_as_string(h, keys_to_test)).to eq('d, b')
29
+ end
30
+
31
+
32
+ it 'should return nil instead of a string for no missing keys' do
33
+ h = { a: 1, c: 1, e: 1}
34
+ keys_to_test = [:e, :c, :a]
35
+ expect(missing_hash_entries_as_string(h, keys_to_test)).to be_nil
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,23 @@
1
+ require_relative '../../spec_helper.rb'
2
+
3
+ require 'trick_bag/validations/object_validations'
4
+
5
+ module TrickBag
6
+ module Validations
7
+ describe ObjectValidations do
8
+
9
+ include ObjectValidations
10
+
11
+ specify 'a missing instance variable should raise an error' do
12
+ vars = [:@this_name_could_not_possibly_be_defined_as_a_real_variable]
13
+ expect(-> { raise_on_nil_instance_vars(self, vars) }).to raise_error
14
+ end
15
+
16
+ specify 'an existing instance variable should NOT raise an error' do
17
+ vars = [:@foo]
18
+ -> { class AbCdEfG; def initialize; @foo = 'hi'; end; end }.()
19
+ expect(-> { raise_on_nil_instance_vars(AbCdEfG.new, vars) }).not_to raise_error
20
+ end
21
+ end
22
+ end
23
+ end
data/trick_bag.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'trick_bag/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "trick_bag"
8
+ spec.version = TrickBag::VERSION
9
+ spec.authors = ["Keith Bennett"]
10
+ spec.email = ["keithrbennett@gmail.com"]
11
+ spec.description = %q{Miscellaneous general useful tools.}
12
+ spec.summary = spec.description
13
+ spec.homepage = "https://github.com/keithrbennett/trick_bag"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'vrsn-ie-dnsruby'
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec"
26
+ spec.add_development_dependency "guard"
27
+ spec.add_development_dependency "guard-rspec"
28
+ end
metadata ADDED
@@ -0,0 +1,194 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trick_bag
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.30.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Keith Bennett
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-03-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: vrsn-ie-dnsruby
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.3'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.3'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: guard
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: guard-rspec
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: Miscellaneous general useful tools.
111
+ email:
112
+ - keithrbennett@gmail.com
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - .gitignore
118
+ - Gemfile
119
+ - Guardfile
120
+ - LICENSE.txt
121
+ - README.md
122
+ - RELEASE_NOTES.md
123
+ - Rakefile
124
+ - lib/trick_bag.rb
125
+ - lib/trick_bag/collections/linked_list.rb
126
+ - lib/trick_bag/enumerables/buffered_enumerable.rb
127
+ - lib/trick_bag/enumerables/compound_enumerable.rb
128
+ - lib/trick_bag/enumerables/filtered_enumerable.rb
129
+ - lib/trick_bag/io/temp_files.rb
130
+ - lib/trick_bag/io/text_mode_status_updater.rb
131
+ - lib/trick_bag/meta/classes.rb
132
+ - lib/trick_bag/numeric/multi_counter.rb
133
+ - lib/trick_bag/numeric/totals.rb
134
+ - lib/trick_bag/operators/operators.rb
135
+ - lib/trick_bag/timing/timing.rb
136
+ - lib/trick_bag/validations/hash_validations.rb
137
+ - lib/trick_bag/validations/object_validations.rb
138
+ - lib/trick_bag/version.rb
139
+ - spec/spec_helper.rb
140
+ - spec/trick_bag/collections/linked_list_spec.rb
141
+ - spec/trick_bag/enumerables/buffered_enumerable_spec.rb
142
+ - spec/trick_bag/enumerables/compound_enumerable_spec.rb
143
+ - spec/trick_bag/enumerables/filtered_enumerable_spec.rb
144
+ - spec/trick_bag/io/temp_files_spec.rb
145
+ - spec/trick_bag/io/text_mode_status_updater_spec.rb
146
+ - spec/trick_bag/meta/classes_spec.rb
147
+ - spec/trick_bag/numeric/multi_counter_spec.rb
148
+ - spec/trick_bag/numeric/totals_spec.rb
149
+ - spec/trick_bag/operators/operators_spec.rb
150
+ - spec/trick_bag/timing/timing_spec.rb
151
+ - spec/trick_bag/validations/hashes_validations_spec.rb
152
+ - spec/trick_bag/validations/object_validations_spec.rb
153
+ - trick_bag.gemspec
154
+ homepage: https://github.com/keithrbennett/trick_bag
155
+ licenses:
156
+ - MIT
157
+ post_install_message:
158
+ rdoc_options: []
159
+ require_paths:
160
+ - lib
161
+ required_ruby_version: !ruby/object:Gem::Requirement
162
+ none: false
163
+ requirements:
164
+ - - ! '>='
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ required_rubygems_version: !ruby/object:Gem::Requirement
168
+ none: false
169
+ requirements:
170
+ - - ! '>='
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ requirements: []
174
+ rubyforge_project:
175
+ rubygems_version: 1.8.25
176
+ signing_key:
177
+ specification_version: 3
178
+ summary: Miscellaneous general useful tools.
179
+ test_files:
180
+ - spec/spec_helper.rb
181
+ - spec/trick_bag/collections/linked_list_spec.rb
182
+ - spec/trick_bag/enumerables/buffered_enumerable_spec.rb
183
+ - spec/trick_bag/enumerables/compound_enumerable_spec.rb
184
+ - spec/trick_bag/enumerables/filtered_enumerable_spec.rb
185
+ - spec/trick_bag/io/temp_files_spec.rb
186
+ - spec/trick_bag/io/text_mode_status_updater_spec.rb
187
+ - spec/trick_bag/meta/classes_spec.rb
188
+ - spec/trick_bag/numeric/multi_counter_spec.rb
189
+ - spec/trick_bag/numeric/totals_spec.rb
190
+ - spec/trick_bag/operators/operators_spec.rb
191
+ - spec/trick_bag/timing/timing_spec.rb
192
+ - spec/trick_bag/validations/hashes_validations_spec.rb
193
+ - spec/trick_bag/validations/object_validations_spec.rb
194
+ has_rdoc: