textquery 0.1.6 → 0.1.7

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.6
1
+ 0.1.7
@@ -1,51 +1,57 @@
1
1
  require 'rubygems'
2
2
  require 'treetop'
3
- require 'oniguruma'
4
3
 
5
- include Oniguruma
6
-
7
- # make it utf-8 compatible
4
+ # make it utf-8 compatible for < 1.9 Ruby
8
5
  if RUBY_VERSION < '1.9'
9
6
  require 'active_support'
7
+ require 'oniguruma'
8
+
9
+ include Oniguruma
10
10
  $KCODE = 'u'
11
+
12
+ RegExp = ORegexp
13
+ RegExp::IGNORECASE = ORegexp::OPTION_IGNORECASE
14
+
15
+ else
16
+ RegExp = Regexp
17
+ RegExp::IGNORECACASE = Regexp::IGNORECASE
11
18
  end
12
19
 
13
- FUZZY = ORegexp.new('(\d)*(~)?([^~]+)(~)?(\d)*$')
20
+ FUZZY = RegExp.new('(\d)*(~)?([^~]+)(~)?(\d)*$')
14
21
 
15
22
  class WordMatch < Treetop::Runtime::SyntaxNode
16
-
23
+
17
24
  @@regex ||= {}
18
25
  @@regex_case ||= {}
19
-
26
+
20
27
  def eval(text, opt)
21
-
22
- fuzzy = FUZZY.match(query)
23
-
24
- q = []
25
- q.push "." if fuzzy[2]
26
- q.push fuzzy[1].nil? ? "*" : "{#{fuzzy[1]}}" if fuzzy[2]
27
- q.push fuzzy[3]
28
- q.push "." if fuzzy[4]
29
- q.push fuzzy[5].nil? ? "*" : "{#{fuzzy[5]}}" if fuzzy[4]
30
- q = q.join
31
-
32
- regex = "(^|#{opt[:delim]})#{q}(#{opt[:delim]}|$)"
33
-
34
- unless @@regex[regex] then
35
- @@regex[regex] = ORegexp.new(regex, :options => OPTION_IGNORECASE)
36
- @@regex_case[regex] = ORegexp.new(regex, nil)
28
+ query = RegExp.escape(text_value)
29
+ qkey = query + opt[:delim]
30
+
31
+ if not @@regex[qkey]
32
+ fuzzy = FUZZY.match(query)
33
+
34
+ q = []
35
+ q.push "." if fuzzy[2]
36
+ q.push fuzzy[1].nil? ? "*" : "{#{fuzzy[1]}}" if fuzzy[2]
37
+ q.push fuzzy[3]
38
+ q.push "." if fuzzy[4]
39
+ q.push fuzzy[5].nil? ? "*" : "{#{fuzzy[5]}}" if fuzzy[4]
40
+ q = q.join
41
+
42
+ regex = "(^|#{opt[:delim]})#{q}(#{opt[:delim]}|$)"
43
+
44
+ @@regex[qkey] = RegExp.new(regex, :options => RegExp::IGNORECASE)
45
+ @@regex_case[qkey] = RegExp.new(regex, nil)
37
46
  end
38
47
 
39
48
  if opt[:ignorecase]
40
- not @@regex[regex].match(text).nil?
49
+ not @@regex[qkey].match(text).nil?
41
50
  else
42
- not @@regex_case[regex].match(text).nil?
51
+ not @@regex_case[qkey].match(text).nil?
43
52
  end
44
53
  end
45
-
46
- def query
47
- ORegexp.escape(text_value)
48
- end
54
+
49
55
  end
50
56
 
51
57
  Treetop.load File.dirname(__FILE__) + "/textquery_grammar"
@@ -88,8 +94,8 @@ class TextQuery
88
94
 
89
95
  private
90
96
 
91
- def update_options(options)
92
- @options = {:delim => ' '}.merge(options)
93
- @options[:delim] = "(#{[@options[:delim]].flatten.map { |opt| ORegexp.escape(opt) }.join("|")})"
94
- end
95
- end
97
+ def update_options(options)
98
+ @options = {:delim => ' '}.merge(options)
99
+ @options[:delim] = "(#{[@options[:delim]].flatten.map { |opt| RegExp.escape(opt) }.join("|")})"
100
+ end
101
+ end
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require "rubygems"
2
4
  require "spec"
3
5
  require "pp"
data/textquery.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{textquery}
8
- s.version = "0.1.6"
8
+ s.version = "0.1.7"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ilya Grigorik"]
12
- s.date = %q{2010-08-18}
12
+ s.date = %q{2010-09-04}
13
13
  s.description = %q{Evaluate any text against a collection of match rules}
14
14
  s.email = %q{ilya@igvita.com}
15
15
  s.extra_rdoc_files = [
@@ -33,7 +33,7 @@ Gem::Specification.new do |s|
33
33
  s.rdoc_options = ["--charset=UTF-8"]
34
34
  s.require_paths = ["lib"]
35
35
  s.rubyforge_project = %q{textquery}
36
- s.rubygems_version = %q{1.3.6}
36
+ s.rubygems_version = %q{1.3.7}
37
37
  s.summary = %q{Evaluate any text against a collection of match rules}
38
38
  s.test_files = [
39
39
  "spec/textquery_spec.rb",
@@ -44,7 +44,7 @@ Gem::Specification.new do |s|
44
44
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
45
45
  s.specification_version = 3
46
46
 
47
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
47
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
48
48
  s.add_runtime_dependency(%q<treetop>, [">= 0"])
49
49
  else
50
50
  s.add_dependency(%q<treetop>, [">= 0"])
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 6
9
- version: 0.1.6
8
+ - 7
9
+ version: 0.1.7
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ilya Grigorik
@@ -14,13 +14,14 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-08-18 00:00:00 -04:00
17
+ date: 2010-09-04 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: treetop
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
24
25
  requirements:
25
26
  - - ">="
26
27
  - !ruby/object:Gem::Version
@@ -60,6 +61,7 @@ rdoc_options:
60
61
  require_paths:
61
62
  - lib
62
63
  required_ruby_version: !ruby/object:Gem::Requirement
64
+ none: false
63
65
  requirements:
64
66
  - - ">="
65
67
  - !ruby/object:Gem::Version
@@ -67,6 +69,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
67
69
  - 0
68
70
  version: "0"
69
71
  required_rubygems_version: !ruby/object:Gem::Requirement
72
+ none: false
70
73
  requirements:
71
74
  - - ">="
72
75
  - !ruby/object:Gem::Version
@@ -76,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
79
  requirements: []
77
80
 
78
81
  rubyforge_project: textquery
79
- rubygems_version: 1.3.6
82
+ rubygems_version: 1.3.7
80
83
  signing_key:
81
84
  specification_version: 3
82
85
  summary: Evaluate any text against a collection of match rules