the_array_comparator 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.yardopts ADDED
@@ -0,0 +1,6 @@
1
+ --verbose
2
+ -
3
+ API-GUIDE.md
4
+ CONTRIBUTIONS.md
5
+ LICENSE.md
6
+ RELEASE_NOTES.md
data/API-GUIDE.md ADDED
@@ -0,0 +1,18 @@
1
+ # API Guide
2
+
3
+ This very brief documentation should give you a good starting point on how to discover the API:
4
+
5
+ ```
6
+ Comparator # Main class dispatching the work
7
+ |
8
+ -- Check, Result, Sample # Helper classes for easier testing
9
+ |
10
+ -- Strategies
11
+ | |
12
+ | -- ContainsAll # Strategies doing the hard work:
13
+ | | # compare data with keywords and
14
+ | -- ... # return the result
15
+ |
16
+ -- Cache # Cache checks for easier retrieval
17
+
18
+ ```
data/README.md CHANGED
@@ -112,10 +112,15 @@ If you wish to write your own comparators you can do so. Just register those cla
112
112
  TheArrayComparator::Comparator.register :my_contains, Strategies::MyContains
113
113
  ```
114
114
 
115
+ ## Further reading
116
+
117
+ Please the the full api-documentation on [rdoc info](http://rdoc.info/github/maxmeyer/the_array_comparator/frames) for further reading.
118
+ I just give you a brief overview of all the available methods. There's also a brief [guide](API-GUIDE.md) about howto discover the API.
119
+
115
120
  ## Contributing
116
121
 
117
- Please see CONTRIBUTIONS.md
122
+ Please see [CONTRIBUTIONS.md](CONTRIBUTIONS.md).
118
123
 
119
124
  ## Copyright
120
125
 
121
- (c) 2013 Max Meyer. All rights reserved. Please also see LICENSE.md
126
+ (c) 2013 Max Meyer. All rights reserved. Please also see [LICENSE.md](LICENSE.md).
data/Rakefile CHANGED
@@ -11,7 +11,7 @@ unless ENV['TRAVIS_CI'] == 'true'
11
11
  end
12
12
 
13
13
  YARD::Rake::YardocTask.new() do |y|
14
- y.options << '--verbose'
14
+ # y.options << '--verbose'
15
15
  end
16
16
 
17
17
  desc 'start tmux'
@@ -0,0 +1,66 @@
1
+ #encoding: utf-8
2
+
3
+ # the main module
4
+ module TheArrayComparator
5
+ #caching class
6
+ class Cache
7
+
8
+ # Create cache
9
+ def initialize
10
+ @cache = []
11
+ @new_objects = false
12
+ end
13
+
14
+ # Add object to cache
15
+ #
16
+ # @param [Object] obj
17
+ # the object which should be added to the cache
18
+ #
19
+ # @return [Object]
20
+ # the object which has beed added
21
+ def add(obj)
22
+ @cache << obj
23
+ @new_objects = true
24
+
25
+ obj
26
+ end
27
+
28
+ # Return all stored objects
29
+ #
30
+ # @return [Array]
31
+ # the cache
32
+ def stored_objects
33
+ @new_objects = false
34
+ @cache
35
+ end
36
+
37
+ # Clear the cache (delete all objects)
38
+ def clear
39
+ @cache = []
40
+ end
41
+
42
+ # Are there new objects
43
+ #
44
+ # @return [TrueClass,FalseClass]
45
+ # the result of the check
46
+ def new_objects?
47
+ @new_objects
48
+ end
49
+
50
+ # Delete an object from cache by number
51
+ #
52
+ # @return
53
+ # the deleted object
54
+ def delete_object(num)
55
+ @cache.delete_at(num)
56
+ end
57
+
58
+ # Request an object from cache by number
59
+ #
60
+ # @return
61
+ # the requested object
62
+ def fetch_object(num)
63
+ @cache[num]
64
+ end
65
+ end
66
+ end
@@ -40,7 +40,7 @@ module TheArrayComparator
40
40
  # @return [Comparator]
41
41
  # a new comparator
42
42
  def initialize
43
- @checks = []
43
+ @cache = Cache.new
44
44
  end
45
45
 
46
46
  # Add a check to test against
@@ -76,12 +76,15 @@ module TheArrayComparator
76
76
  strategy_klass = Comparator.comparators[type]
77
77
  check = Check.new(strategy_klass,sample)
78
78
 
79
- @checks << check
80
- return check
79
+ @cache.add check
81
80
  end
82
81
 
82
+ # The result of all checks defined
83
+ #
84
+ # @return [Result]
85
+ # the result class with all the data need for further analysis
83
86
  def result
84
- @checks.each { |c| return Result.new(c.sample) unless c.success? }
87
+ @cache.stored_objects.each { |c| return Result.new(c.sample) unless c.success? }
85
88
 
86
89
  Result.new
87
90
  end
@@ -100,8 +103,8 @@ module TheArrayComparator
100
103
  # @param [Integer] number
101
104
  # the index of the check which should be deleted
102
105
  def delete_check(number)
103
- if @checks[number]
104
- @checks.delete_at(number)
106
+ if @cache.fetch_object(number)
107
+ @cache.delete_object(number)
105
108
  else
106
109
  raise Exceptions::CheckDoesNotExist, "You tried to delete a check, which does not exist!"
107
110
  end
@@ -117,7 +120,7 @@ module TheArrayComparator
117
120
  # @return [Array]
118
121
  # all available checks
119
122
  def list_checks
120
- @checks
123
+ @cache.stored_objects
121
124
  end
122
125
  end
123
126
  end
@@ -17,10 +17,23 @@ module TheArrayComparator
17
17
  # description of the probe
18
18
  attr_accessor :data, :keywords, :exceptions, :tag
19
19
 
20
- def initialize(data=[],keywords=[],exceptions=[],tag=nil)
21
- @keywords = keywords
22
- @data = data
23
- @exceptions = exceptions
20
+ # New sample
21
+ #
22
+ # @param [Array] data ([])
23
+ # the data to look for keywords
24
+ #
25
+ # @param [Set] keywords (Set.new)
26
+ # the keywords (singular values/arrays will be transformed to a set)
27
+ #
28
+ # @param [Set] exceptions (Set.new)
29
+ # the exceptions (singular values/arrays will be transformed to a set)
30
+ #
31
+ # @param [String] tag (nil)
32
+ # a tag to identify a sample
33
+ def initialize(data=[],keywords=Set.new,exceptions=Set.new,tag=nil)
34
+ @keywords = Set.new( [ *keywords ] )
35
+ @data = *data
36
+ @exceptions = Set.new( [ *exceptions ] )
24
37
  @tag = tag
25
38
  end
26
39
 
@@ -1,6 +1,4 @@
1
- #encoding: utf-8
2
-
3
1
  #main TheArrayComparator
4
2
  module TheArrayComparator
5
- VERSION = '0.1.1'
6
- end
3
+ VERSION = '0.2.0'
4
+ end
@@ -6,6 +6,7 @@ require 'forwardable'
6
6
 
7
7
  require 'the_array_comparator/version'
8
8
  require 'the_array_comparator/exceptions'
9
+ require 'the_array_comparator/cache'
9
10
  require 'the_array_comparator/sample'
10
11
  require 'the_array_comparator/check'
11
12
  require 'the_array_comparator/result'
@@ -0,0 +1,89 @@
1
+ #enconding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Cache do
5
+
6
+ let(:cache) { Cache.new }
7
+
8
+ it "adds abitrary objects to cache" do
9
+ expect {
10
+ cache.add %w{obj}
11
+ cache.add('obj')
12
+ }.to_not raise_error
13
+ end
14
+
15
+ it "returns all cached objects" do
16
+ objects = []
17
+
18
+ objects << cache.add('obj')
19
+ objects << cache.add('obj')
20
+ objects << cache.add('obj')
21
+
22
+ expect(cache.stored_objects).to eq(objects)
23
+ end
24
+
25
+ it "clears cache" do
26
+ cache.add('obj')
27
+ cache.add('obj')
28
+ cache.add('obj')
29
+ expect(cache.stored_objects.size).to eq(3)
30
+
31
+ cache.clear
32
+ expect(cache.stored_objects.size).to eq(0)
33
+ end
34
+
35
+ it "tells the requester if there are new objects" do
36
+ cache.add('obj')
37
+ expect(cache.new_objects?).to eq(true)
38
+ end
39
+
40
+ it "tells the requester if there __no__ new objects" do
41
+ cache.add('obj')
42
+ cache.stored_objects
43
+ expect(cache.new_objects?).to eq(false)
44
+ end
45
+
46
+ it "works with sub-sequent requests to the cache as well" do
47
+ cache.add('obj')
48
+ cache.stored_objects
49
+ cache.add('obj')
50
+ expect(cache.new_objects?).to eq(true)
51
+
52
+ cache.add('obj')
53
+ cache.stored_objects
54
+ cache.add('obj')
55
+ cache.stored_objects
56
+ expect(cache.new_objects?).to eq(false)
57
+ end
58
+
59
+ it "returns the same objecs if requested multiple times" do
60
+ cache.add('obj')
61
+ cache.add('obj')
62
+ run1 = cache.stored_objects
63
+ run2 = cache.stored_objects
64
+
65
+ expect(run1).to be(run2)
66
+ expect(run1).to eq(run2)
67
+ end
68
+
69
+ it "deletes specific objects from cache (by number)" do
70
+ cache.add('obj')
71
+ c_created = cache.add('obj')
72
+ cache.add('obj')
73
+
74
+ c_deleted = cache.delete_object(1)
75
+
76
+ expect(c_created).to eq(c_deleted)
77
+ end
78
+
79
+ it "gets you a specific object" do
80
+ cache.add('obj')
81
+ c_created = cache.add('obj')
82
+ cache.add('obj')
83
+
84
+ c_fetched = cache.fetch_object(1)
85
+
86
+ expect(c_created).to eq(c_fetched)
87
+ end
88
+
89
+ end
@@ -91,7 +91,7 @@ describe Comparator do
91
91
  expect(result).to eq(true)
92
92
  end
93
93
 
94
- it "fails if a least one subtest fails", :test => true do
94
+ it "fails if a least one subtest fails" do
95
95
  comparator = Comparator.new
96
96
  data = %w{ a b c d }
97
97
  keyword_overlap = %w{ a }
@@ -182,7 +182,7 @@ describe Comparator do
182
182
  expect(result.of_checks).to eq(true)
183
183
  end
184
184
 
185
- it "tells you which check has failed and made the whole thing failed" do
185
+ it "tells you which check has failed and made the whole thing failed" , :test => true do
186
186
  comparator = Comparator.new
187
187
  data = %w{ a b c d }
188
188
  keyword_successfull = %w{ a b }
data/spec/sample_spec.rb CHANGED
@@ -17,8 +17,22 @@ describe Sample do
17
17
  sample = Sample.new(data, keywords, exceptions, tag)
18
18
 
19
19
  expect(sample.data).to eq(data)
20
- expect(sample.keywords).to eq(keywords)
21
- expect(sample.exceptions).to eq(exceptions)
20
+ expect(sample.keywords).to eq(Set.new(keywords))
21
+ expect(sample.exceptions).to eq(Set.new(exceptions))
22
22
  expect(sample.tag).to eq(tag)
23
23
  end
24
+
25
+ it "takes singular values and return them into arrays" do
26
+ data = 'data'
27
+ keywords = 'keywords'
28
+ exceptions = 'exceptions'
29
+
30
+ sample = Sample.new(data, keywords, exceptions)
31
+
32
+ expect(sample.data).to eq([ data ])
33
+ expect(sample.keywords).to eq(Set.new( [ keywords ] ) )
34
+ expect(sample.exceptions).to eq(Set.new( [ exceptions ] ) )
35
+ end
36
+
37
+
24
38
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: the_array_comparator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -38,6 +38,8 @@ files:
38
38
  - .rspec
39
39
  - .ruby-version
40
40
  - .travis.yml
41
+ - .yardopts
42
+ - API-GUIDE.md
41
43
  - CONTRIBUTIONS.md
42
44
  - Gemfile
43
45
  - Gemfile.lock
@@ -49,6 +51,7 @@ files:
49
51
  - gemfiles/Gemfile.default
50
52
  - gemfiles/Gemfile.travis
51
53
  - lib/the_array_comparator.rb
54
+ - lib/the_array_comparator/cache.rb
52
55
  - lib/the_array_comparator/check.rb
53
56
  - lib/the_array_comparator/comparator.rb
54
57
  - lib/the_array_comparator/exceptions.rb
@@ -70,6 +73,7 @@ files:
70
73
  - script/console
71
74
  - script/terminal
72
75
  - spec/benchmark/benchmark_spec.rb
76
+ - spec/cache_spec.rb
73
77
  - spec/check_spec.rb
74
78
  - spec/comparator/base_spec.rb
75
79
  - spec/comparator/comparator_spec.rb
@@ -113,6 +117,7 @@ specification_version: 3
113
117
  summary: you need to compare arrays? then this gem is very suitable for you.
114
118
  test_files:
115
119
  - spec/benchmark/benchmark_spec.rb
120
+ - spec/cache_spec.rb
116
121
  - spec/check_spec.rb
117
122
  - spec/comparator/base_spec.rb
118
123
  - spec/comparator/comparator_spec.rb