ruby-nuggets 0.1.7.234 → 0.1.8.235

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.
data/README CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  == VERSION
4
4
 
5
- This documentation refers to ruby-nuggets version 0.1.7
5
+ This documentation refers to ruby-nuggets version 0.1.8
6
6
 
7
7
 
8
8
  == DESCRIPTION
@@ -25,3 +25,45 @@
25
25
  ###############################################################################
26
26
  #++
27
27
 
28
+ require 'rubygems'
29
+ require 'text'
30
+
31
+ module Enumerable
32
+
33
+ # call-seq:
34
+ # enum.agrep(pattern[, distance]) => anArray
35
+ #
36
+ # Returns an array of every element in _enum_ for which the Levenshtein
37
+ # distance between +pattern+ and +element+ is at most +distance+. Hence,
38
+ # errors in the match are allowed, similar to what the UNIX tool agrep does.
39
+ #
40
+ # LIMITATIONS:
41
+ #
42
+ # - Only strings are allowed as +pattern+. Regular expressions are reverted
43
+ # to their respective source. (Equivalent to <tt>agrep -k</tt>)
44
+ # - Only works with string elements in _enum_. (Calls +to_s+ on each element)
45
+ # - The cost for individual error types (substitution, insertion, deletion)
46
+ # cannot be adjusted.
47
+ def agrep(pattern, distance = 0, cost = 1)
48
+ pattern = pattern.source if pattern.is_a?(Regexp)
49
+
50
+ select { |obj|
51
+ Text::Levenshtein.distance(pattern, obj.to_s) * cost <= distance
52
+ }
53
+ end
54
+
55
+ end
56
+
57
+ if $0 == __FILE__
58
+ e = %w[quux quuux quix quixx]
59
+ p e
60
+
61
+ p e.agrep(/quux/)
62
+ p e.agrep(/quux/, 1)
63
+ p e.agrep(/quux/, 2)
64
+
65
+ p e.grep(/qu.x/)
66
+ p e.agrep(/qu.x/)
67
+
68
+ p [123, 124, 1233].agrep(/123/, 1)
69
+ end
@@ -4,7 +4,7 @@ module Nuggets
4
4
 
5
5
  MAJOR = 0
6
6
  MINOR = 1
7
- TINY = 7
7
+ TINY = 8
8
8
 
9
9
  class << self
10
10
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-nuggets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7.234
4
+ version: 0.1.8.235
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jens Wille
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-04-25 00:00:00 +02:00
12
+ date: 2008-04-26 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -24,59 +24,59 @@ extra_rdoc_files:
24
24
  - ChangeLog
25
25
  - README
26
26
  files:
27
- - lib/nuggets/integer/to_binary_s.rb
28
- - lib/nuggets/integer/factorial.rb
29
- - lib/nuggets/version.rb
30
- - lib/nuggets/object/singleton_class.rb
31
- - lib/nuggets/object/blank.rb
32
- - lib/nuggets/enumerable/minmax.rb
33
27
  - lib/nuggets/all.rb
34
- - lib/nuggets/string/sub_with_md.rb
28
+ - lib/nuggets/version.rb
29
+ - lib/nuggets/file/which.rb
30
+ - lib/nuggets/integer/factorial.rb
31
+ - lib/nuggets/integer/to_binary_s.rb
32
+ - lib/nuggets/array/to_hash.rb
33
+ - lib/nuggets/array/shuffle.rb
34
+ - lib/nuggets/array/format.rb
35
+ - lib/nuggets/array/in_order.rb
36
+ - lib/nuggets/array/combination.rb
37
+ - lib/nuggets/array/flatten_once.rb
38
+ - lib/nuggets/array/rand.rb
39
+ - lib/nuggets/array/monotone.rb
40
+ - lib/nuggets/uri/exist.rb
41
+ - lib/nuggets/uri/content_type.rb
42
+ - lib/nuggets/proc/bind.rb
43
+ - lib/nuggets/string/word_wrap.rb
35
44
  - lib/nuggets/string/msub.rb
36
45
  - lib/nuggets/string/case.rb
46
+ - lib/nuggets/string/sub_with_md.rb
37
47
  - lib/nuggets/string/evaluate.rb
38
- - lib/nuggets/string/word_wrap.rb
39
48
  - lib/nuggets/string/nsub.rb
40
49
  - lib/nuggets/string/capitalize_first.rb
41
- - lib/nuggets/hash/in_order.rb
42
- - lib/nuggets/hash/insert.rb
43
- - lib/nuggets/proc/bind.rb
44
- - lib/nuggets/array/rand.rb
45
- - lib/nuggets/array/to_hash.rb
46
- - lib/nuggets/array/flatten_once.rb
47
- - lib/nuggets/array/in_order.rb
48
- - lib/nuggets/array/shuffle.rb
49
- - lib/nuggets/array/monotone.rb
50
- - lib/nuggets/array/format.rb
51
- - lib/nuggets/array/combination.rb
50
+ - lib/nuggets/object/blank.rb
51
+ - lib/nuggets/object/singleton_class.rb
52
52
  - lib/nuggets/numeric/between.rb
53
53
  - lib/nuggets/numeric/signum.rb
54
54
  - lib/nuggets/numeric/to_multiple.rb
55
- - lib/nuggets/util/ansicolor2css.rb
56
- - lib/nuggets/util/content_type.rb
57
55
  - lib/nuggets/util/dotted_decimal.rb
58
56
  - lib/nuggets/util/i18n.rb
59
- - lib/nuggets/file/which.rb
60
- - lib/nuggets/uri/content_type.rb
61
- - lib/nuggets/uri/exist.rb
57
+ - lib/nuggets/util/ansicolor2css.rb
58
+ - lib/nuggets/util/content_type.rb
59
+ - lib/nuggets/enumerable/minmax.rb
60
+ - lib/nuggets/enumerable/agrep.rb
61
+ - lib/nuggets/hash/in_order.rb
62
+ - lib/nuggets/hash/insert.rb
62
63
  - COPYING
63
- - HEADER
64
+ - Rakefile
64
65
  - README
65
66
  - ChangeLog
66
- - Rakefile
67
67
  has_rdoc: true
68
68
  homepage: http://prometheus.rubyforge.org/ruby-nuggets
69
69
  post_install_message:
70
70
  rdoc_options:
71
71
  - --line-numbers
72
- - --all
72
+ - --main
73
+ - README
73
74
  - --inline-source
74
75
  - --title
75
76
  - ruby-nuggets Application documentation
76
- - --main
77
- - README
78
77
  - --charset
79
78
  - UTF-8
79
+ - --all
80
80
  require_paths:
81
81
  - lib
82
82
  required_ruby_version: !ruby/object:Gem::Requirement