fuzzy_string 0.0.2.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
  SHA1:
3
- metadata.gz: 73a34cf02fb947f066a762738cac66355bf2cc99
4
- data.tar.gz: a2d2c08aef3e4b5050e4a7424b9576467064497a
3
+ metadata.gz: bd20e09ff3e7e38a255c27b9780e08f0c2022e96
4
+ data.tar.gz: b15e19a162affbf1b33c3b2d70488d938fcdc35b
5
5
  SHA512:
6
- metadata.gz: d1316195174c23eb0cc380d3fe26caa637ef22a5a190cb036a06742fa820bf7f284073420bb8f0826197fb736cbbee502f75e53c4b8b39ac1e660d35ad5da911
7
- data.tar.gz: ca346b8a5bb3e834e643a395aead1cd65382d89a6dafcf0a6e3e224a956bbf1bbdaab252bce0cfc0a5d4e04a2fdc547670201154a476696f84e19938e84263f8
6
+ metadata.gz: a87e478b2ca14088b9b6878097f30e843a24e24edb2a30766774b6e60e9342b2ecdf3a6faa816a22d1065f4af9b0c1b8349a311bcafe0a8dd951ff6249a7300f
7
+ data.tar.gz: 32fb2af62beb4459061dca962cc40c437642a1b838c7e30dfc63e1daa908004786c6e06df5981426f2470528acc74f1b4d7e6eb2861e8ec16a69b49eee15de93
@@ -1,8 +1,8 @@
1
1
  class FuzzyString::AdjustedScore
2
2
  def self.rank(first,second) new(first,second).rank end
3
3
  def initialize(first,second)
4
- @first = first
5
- @second = second
4
+ @first = first.length < second.length ? first : second
5
+ @second = first.length < second.length ? second : first
6
6
  end
7
7
  def rank
8
8
  return 0 if (@first == @second)
@@ -11,7 +11,9 @@ class FuzzyString::AdjustedScore
11
11
  adjusted_levenschtein_distance
12
12
  end
13
13
  def adjusted_levenschtein_distance
14
- pieces = @first.split(/#{@second.chars.to_a.join('(.*?)')}/i)
14
+ special_chars = [")", "(", "]", "[", "}", "{", ".", "?", "+", "*"]
15
+ regex = /#{@second.chars.to_a.map{|el| special_chars.includes?(el) ? "\\"+el : el}.join('(.*?)')}/i
16
+ pieces = @first.split(regex)
15
17
  score = pieces[0][-1] == ' ' ? -1 : 0
16
18
  score += pieces[0..@second.length - 1].uniq == [''] ? -@first.length.to_f / 2 : 0
17
19
  score += (pieces[@second.length] || [])[0] == ' ' ? -@first.length.to_f / 2 : 0
@@ -1,3 +1,3 @@
1
1
  module FuzzyString
2
- VERSION = "0.0.2.1"
2
+ VERSION = "1.0.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fuzzy_string
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Moody
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-29 00:00:00.000000000 Z
11
+ date: 2017-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -122,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
122
  version: '0'
123
123
  requirements: []
124
124
  rubyforge_project:
125
- rubygems_version: 2.2.1
125
+ rubygems_version: 2.4.3
126
126
  signing_key:
127
127
  specification_version: 4
128
128
  summary: Relative ranking system for strings.