fuzzyfinder 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/fuzzyfinder.rb +15 -0
  3. metadata +44 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 017b1cdc9a590e44e4792766e57e9dfe8ab248b3
4
+ data.tar.gz: 430498df1dac01bb7e97da23eda1ad19b933c914
5
+ SHA512:
6
+ metadata.gz: 4b52dde5a4fe59b97983960db2353113b18ecb890c9965443b250a71997b9ed8032fe1a9581dfd011e316760799bc9030452ec47ffd892064588b9f5d4b21034
7
+ data.tar.gz: b748689fc24d7132b75a3c0ce8840c56a280aa7b814b4358339e9402dbc3d8899e64c8e4d8de9851efcfd924b4e79de0a6c72f6f8e1289d2e6989d264d91eca7
@@ -0,0 +1,15 @@
1
+ class Fuzzyfinder
2
+ def self.find(user_input, collection)
3
+ user_input = user_input.to_s if user_input.is_a? Numeric
4
+ temporary_suggestions, suggestions = [], []
5
+ pattern = user_input.split('').join('.*?')
6
+ collection.each do |item|
7
+ matches = item.scan(/#{pattern}/)
8
+ if matches.any?
9
+ temporary_suggestions.push([matches.last.length, Regexp.last_match.begin(0), item])
10
+ end
11
+ end
12
+ temporary_suggestions.sort!.each { |e| suggestions.push(e.last) }
13
+ suggestions
14
+ end
15
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fuzzyfinder
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Matheus Rosa
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-10-06 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Matches partial string entries from a list of strings.
14
+ email: matheusdsrosa@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/fuzzyfinder.rb
20
+ homepage: https://rubygems.org/gems/fuzzyfinder
21
+ licenses:
22
+ - mit
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.4.6
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: Fuzzy Finder
44
+ test_files: []