identity_parade 0.1.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9b6fe64eaee5917d1f7f7863c91e3bc52c66db275f5c12d528a95a813fd499e7
4
- data.tar.gz: c965c706a93b5f372c57c540a43d45f13c0d835da4a81ddafd24c8ebc81d3bf1
3
+ metadata.gz: 7380c519639022df0efa2b685bab2d9572c9f3acbf9e86a27cb2cd49a35df75c
4
+ data.tar.gz: 9aaf25c04855146be3e8c5776e3cfd100699202b3ad7bcdafa87b500ca6a628e
5
5
  SHA512:
6
- metadata.gz: 5203135418469da69bb62cdaeeb0bd951b2485a8e1f0828cef21ff18fa0304bc1607c160a043f7c52b558c65273edf106241d9b737786b4732ae1b85d1bc5f03
7
- data.tar.gz: c9792595e20de8b7c84b7397951c9a95237f063b85a797edeaf23a652a71a82112d7083f2c784dbadbd163330f5cafe63be9dc1dd047ec74875a2c5182ab1fa7
6
+ metadata.gz: c0a55315ad2c80c0858d829bbb8df5c82f34dcd66f418e0e98ef9dca4a8fc8ba31c36e65166cca11078ddeb0503b658a0481995e6e98e47de9faeafc269f61de
7
+ data.tar.gz: a1577e814ddaecd0829e5bce5d81d688883e8570cae39d63a139256f9ae27efef4e515251c99c9fb9c055a64fcf67bdcfe6c574886fabfab71f37423f00a5bc9
data/README.md CHANGED
@@ -20,25 +20,51 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
+ IdentityParade has a very simple API. There are basically only two methods:
24
+
23
25
  ``` ruby
24
- IdentityParade.match(original, possible_duplicate)
26
+ # Checks the similarity between to arguments. Returns a number between
27
+ # 0 and 1. 0 is no similarity and 1 is a complete duplicate.
28
+ IdentityParade.match(arg1, arg2)
25
29
  # => 0.95
26
30
 
27
- IdentityParade.match?(original, possible_duplicate)
31
+ # When matching score is equal or greater than the global +matching_score+
32
+ # it returns true - otherwise false.
33
+ IdentityParade.match?(arg1, arg2)
28
34
  # => true
29
35
  ```
30
36
 
37
+ ## Configuration
38
+
39
+ IdentityParade can be configured by the `configure` method:
40
+
41
+ ``` ruby
42
+ IdentityParade.configure do |config|
43
+ # Blacklist some keys in a hash that should not be compared.
44
+ config.blacklisted_keys = %w[id created_at updated_at]
45
+ # Set the global match score to 80%
46
+ config.match_score = 0.80
47
+ end
48
+ ```
31
49
 
32
50
  ## Development
33
51
 
34
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
52
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run
53
+ `rake spec` to run the tests. You can also run `bin/console` for an interactive
54
+ prompt that will allow you to experiment.
35
55
 
36
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
56
+ To install this gem onto your local machine, run `bundle exec rake install`. To
57
+ release a new version, update the version number in `version.rb`, and then run
58
+ `bundle exec rake release`, which will create a git tag for the version, push
59
+ git commits and tags, and push the `.gem` file to
60
+ [rubygems.org](https://rubygems.org).
37
61
 
38
62
  ## Contributing
39
63
 
40
- Bug reports and pull requests are welcome on GitHub at https://github.com/henvo/identity_parade.
64
+ Bug reports and pull requests are welcome on GitHub at
65
+ https://github.com/henvo/identity_parade.
41
66
 
42
67
  ## License
43
68
 
44
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
69
+ The gem is available as open source under the terms of the [MIT
70
+ License](https://opensource.org/licenses/MIT).
@@ -9,8 +9,10 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ['Henning Vogt']
10
10
  spec.email = ['git@henvo.de']
11
11
 
12
- spec.summary = 'Find duplicates or near-duplicates of.'
13
- spec.description = 'This gem allows to compare two hashes.'
12
+ spec.summary = 'Checks basic data types for similarity.'
13
+ spec.description = 'IdentityParade allows you to compare two basic data ' \
14
+ 'types, e.g. hashes, arrays, numbers and strings.' \
15
+ 'It returns a matching score or a boolean.'
14
16
  spec.homepage = 'https://github.com/henvo/identity_parade'
15
17
  spec.license = 'MIT'
16
18
 
@@ -37,4 +39,5 @@ Gem::Specification.new do |spec|
37
39
  spec.add_development_dependency 'rake', '~> 10.0'
38
40
  spec.add_development_dependency 'reek', '~> 4.8'
39
41
  spec.add_development_dependency 'rspec', '~> 3.0'
42
+ spec.add_development_dependency 'simplecov', '~> 0.16'
40
43
  end
@@ -8,16 +8,19 @@ module IdentityParade
8
8
  @right = right
9
9
  end
10
10
 
11
+ # @return [Float] the matching score
11
12
  def score
12
13
  return unless Kernel.const_defined?(matcher_class_name)
13
14
 
14
15
  matcher.new(@left, @right).score
15
16
  end
16
17
 
18
+ # @return [Class] The matcher class
17
19
  def matcher
18
20
  matcher_class_name.constantize
19
21
  end
20
22
 
23
+ # @return [String] the matcher class name
21
24
  def matcher_class_name
22
25
  "identity_parade/matchers/#{@left.class.name.underscore}_matcher".classify
23
26
  end
@@ -1,5 +1,8 @@
1
1
  module IdentityParade
2
- # The base class for all matchers
2
+ # The base class for all matchers implements the basic interface for all
3
+ # matchers.
4
+ #
5
+ # Every matcher MUST implement a score method that returns a Number.
3
6
  class Matcher
4
7
  attr_reader :left, :right
5
8
 
@@ -3,9 +3,7 @@ module IdentityParade
3
3
  # This matcher checks the similarity of booleans
4
4
  class BooleanMatcher < Matcher
5
5
  def score
6
- return 0 unless [TrueClass, FalseClass].include?(@right.class)
7
-
8
- @left == @right ? 1 : 0
6
+ @left.class == @right.class ? 1 : 0
9
7
  end
10
8
  end
11
9
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IdentityParade
4
- VERSION = '0.1.1'.freeze
4
+ VERSION = '1.0.0'.freeze
5
5
  end
@@ -14,15 +14,15 @@ require 'identity_parade/matchers/boolean_matcher'
14
14
  require 'identity_parade/matchers/true_class_matcher'
15
15
  require 'identity_parade/matchers/false_class_matcher'
16
16
 
17
-
18
17
  # This gem allows to compare two types.
19
18
  module IdentityParade
20
19
  class << self
21
- # :reek;Attribute because we want to share the config
20
+ # :reek:Attribute because we want to share the config
22
21
  def config
23
22
  @config ||= RecursiveOpenStruct.new
24
23
  end
25
24
 
25
+ # Allows to configure the global configuration
26
26
  def configure
27
27
  yield(config)
28
28
  end
@@ -30,10 +30,23 @@ module IdentityParade
30
30
 
31
31
  module_function
32
32
 
33
+ # Get the matching score of two basic data types
34
+ #
35
+ # @param left [Number, String, Array, TrueClass, FalseClass] left
36
+ # @param right [Number, String, Array, TrueClass, FalseClass] right
37
+ #
38
+ # @return [Float] the matching score
33
39
  def match(left, right)
34
40
  IdentityParade::Match.new(left, right).score
35
41
  end
36
42
 
43
+ # Checks if a matching score is higher than the globally configure
44
+ # match_score.
45
+ #
46
+ # @param left [Number, String, Array, TrueClass, FalseClass] left
47
+ # @param right [Number, String, Array, TrueClass, FalseClass] right
48
+ #
49
+ # @return [TrueClass, FalseClass] the result
37
50
  def match?(left, right)
38
51
  match(left, right) >= IdentityParade.config.match_score
39
52
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: identity_parade
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henning Vogt
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-04-25 00:00:00.000000000 Z
11
+ date: 2018-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -128,7 +128,22 @@ dependencies:
128
128
  - - "~>"
129
129
  - !ruby/object:Gem::Version
130
130
  version: '3.0'
131
- description: This gem allows to compare two hashes.
131
+ - !ruby/object:Gem::Dependency
132
+ name: simplecov
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - "~>"
136
+ - !ruby/object:Gem::Version
137
+ version: '0.16'
138
+ type: :development
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - "~>"
143
+ - !ruby/object:Gem::Version
144
+ version: '0.16'
145
+ description: IdentityParade allows you to compare two basic data types, e.g. hashes,
146
+ arrays, numbers and strings.It returns a matching score or a boolean.
132
147
  email:
133
148
  - git@henvo.de
134
149
  executables: []
@@ -185,5 +200,5 @@ rubyforge_project:
185
200
  rubygems_version: 2.7.6
186
201
  signing_key:
187
202
  specification_version: 4
188
- summary: Find duplicates or near-duplicates of.
203
+ summary: Checks basic data types for similarity.
189
204
  test_files: []