arraybooster 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/arraybooster.rb +39 -0
  2. metadata +25 -44
@@ -1,5 +1,44 @@
1
+ # encoding: utf-8
2
+ # Author: Edwin Rozario <rozarioed@gmail.com>
3
+ require 'set'
4
+
1
5
  class Array
2
6
 
7
+ def word_letter_pairs str
8
+ @similarity_pairs[str] ||=
9
+ str.upcase.split(/\s+/).map{ |word|
10
+ (0 ... (word.length - 1)).map { |i| word[i, 2] }
11
+ }.flatten.freeze
12
+ end
13
+
14
+ #Using string similarity described by Simon White.
15
+ #Same functions in gem text from class WhiteSimilarity.
16
+ def similarity str1, str2
17
+ pairs1 = word_letter_pairs(str1)
18
+ pairs2 = word_letter_pairs(str2).dup
19
+
20
+ union = pairs1.length + pairs2.length
21
+
22
+ intersection = 0
23
+ pairs1.each do |pair1|
24
+ if index = pairs2.index(pair1)
25
+ intersection += 1
26
+ pairs2.delete_at(index)
27
+ end
28
+ end
29
+
30
+ (2.0 * intersection) / union
31
+ end
32
+
33
+ def similars subject
34
+ @similarity_pairs = {}
35
+ result = []
36
+ self.each do |element|
37
+ result << element if similarity(subject.to_s, element.to_s) > 0.0
38
+ end
39
+ result
40
+ end
41
+
3
42
  def anypop list, numbers = nil
4
43
  if numbers.nil?
5
44
  popped = list.pop
metadata CHANGED
@@ -1,68 +1,49 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: arraybooster
3
- version: !ruby/object:Gem::Version
4
- hash: 29
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 0
9
- - 1
10
- version: 0.0.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Edwin Rozario
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-04-24 00:00:00 +05:30
19
- default_executable:
12
+ date: 2012-08-22 00:00:00.000000000 Z
20
13
  dependencies: []
21
-
22
- description: Features such as Substitute, Rpush, Rpop, Lpush, Lpop, PriorityPush added to Array
23
- email:
14
+ description: Features such as Substitute, Rpush, Rpop, Lpush, Lpop, PriorityPush added
15
+ to Array. Also enables to find similar elemets.
16
+ email:
24
17
  - rozarioed@gmail.com
25
18
  executables: []
26
-
27
19
  extensions: []
28
-
29
20
  extra_rdoc_files: []
30
-
31
- files:
21
+ files:
32
22
  - lib/arraybooster.rb
33
- has_rdoc: true
34
23
  homepage: https://github.com/EdwinRozario/ArrayBooster
35
24
  licenses: []
36
-
37
25
  post_install_message:
38
26
  rdoc_options: []
39
-
40
- require_paths:
27
+ require_paths:
41
28
  - lib
42
- required_ruby_version: !ruby/object:Gem::Requirement
29
+ required_ruby_version: !ruby/object:Gem::Requirement
43
30
  none: false
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- hash: 3
48
- segments:
49
- - 0
50
- version: "0"
51
- required_rubygems_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
36
  none: false
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- hash: 3
57
- segments:
58
- - 0
59
- version: "0"
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
60
41
  requirements: []
61
-
62
42
  rubyforge_project:
63
- rubygems_version: 1.3.7
43
+ rubygems_version: 1.8.24
64
44
  signing_key:
65
45
  specification_version: 3
66
- summary: Array Extention
46
+ summary: Features such as Substitute, Rpush, Rpop, Lpush, Lpop, PriorityPush added
47
+ to Array. Also enables to find similar elemets.
67
48
  test_files: []
68
-
49
+ has_rdoc: