regexp_trie 0.3.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 262475174a73825ef9b5bfaa579b082876858b0f
4
- data.tar.gz: e38772708d15f5a0ad150af20d46e0d786422d92
3
+ metadata.gz: 6f450dfb8edc505285c6a6a7558139b05bf68892
4
+ data.tar.gz: 81bb161f664b59f34c4515af86fe5580a0c445ef
5
5
  SHA512:
6
- metadata.gz: 7003a856fd99399cf1e566a8a30847183edac6feb06f25173882ebe4aca9655c7cdba435a617fce7af4ff12f315234aee294b1d63ec319bb0c87aa65e177cb08
7
- data.tar.gz: ed1a28a0651d084aa186b9a1519fe2beeb06f7ebcbcfc18f712865b64d8d64e19ab99cad67d0bb89607083d5ab623872541e58d89a3d550bb4d85eb036501756
6
+ metadata.gz: 598aaa75d15f81c979fc475000a379223b1e62a1dc332d255ad350fcf70cfff7064e81257e919f4bf6160981b666d5bc5b18dd12dde624fd3f7008e41ac2c84f
7
+ data.tar.gz: 57e92cb52bcc506f94f622e46e9d43857352ad692ad6229d639d42c308ec510fce16bed64dcc000e15fbba18b57ff1ec681a5938a021774636820283d786c5e5
data/CHANGES.md CHANGED
@@ -1,5 +1,14 @@
1
1
  Revision history of the RegexpTrie gem
2
2
 
3
+ ## v1.0.0 - 2016/11/14
4
+
5
+ - Add a method to get the union pattern as `String`, not as `Regexp`
6
+ - `RegexpTrie.new(*patterns).to_source`
7
+
8
+ ## v0.3.0 - 2016/04/20
9
+
10
+ - Fixed #1
11
+
3
12
  ## v0.2.0 - 2016/01/22
4
13
 
5
14
  - Tweaks for documentation
data/lib/regexp_trie.rb CHANGED
@@ -6,50 +6,55 @@ class RegexpTrie
6
6
  # @param [Fixnum,Boolean] option The second argument of Regexp.new()
7
7
  # @return [Regexp]
8
8
  def self.union(*strings, option: nil)
9
- rt = new
10
- strings.flatten.each do |arg|
11
- rt.add(arg)
12
- end
13
- rt.to_regexp(option)
9
+ new(*strings).to_regexp(option)
14
10
  end
15
11
 
16
- def initialize
12
+ def initialize(*strings)
17
13
  @head = {}
14
+
15
+ strings.flatten.each do |str|
16
+ add(str)
17
+ end
18
18
  end
19
19
 
20
20
  # @param [String] str
21
21
  def add(str)
22
- return self unless str && str.size > 0
22
+ return self if !str || str.empty?
23
23
 
24
24
  entry = @head
25
25
  str.each_char do |c|
26
26
  entry[c] ||= {}
27
27
  entry = entry[c]
28
28
  end
29
- entry[:end] = true
29
+ entry[:end] = nil
30
30
  self
31
31
  end
32
32
 
33
- # @return [Regexp]
34
- def to_regexp(option = nil)
33
+ # @return [String]
34
+ def to_source
35
35
  if @head.empty?
36
- Regexp.union
36
+ Regexp.union.source
37
37
  else
38
- Regexp.new(build(@head), option)
38
+ build(@head)
39
39
  end
40
40
  end
41
41
 
42
+ # @return [Regexp]
43
+ def to_regexp(option = nil)
44
+ Regexp.new(to_source, option)
45
+ end
46
+
42
47
  private
43
48
 
44
49
  def build(entry)
45
- return nil if entry[:end] && entry.size == 1
50
+ return nil if entry.include?(:end) && entry.size == 1
46
51
 
47
52
  alt = []
48
53
  cc = []
49
54
  q = false
50
55
 
51
56
  entry.keys.each do |c|
52
- if entry[c].kind_of?(Hash)
57
+ if entry[c]
53
58
  recurse = build(entry[c])
54
59
  qc = Regexp.quote(c)
55
60
  if recurse
@@ -1,3 +1,3 @@
1
1
  class RegexpTrie
2
- VERSION = "0.3.0"
2
+ VERSION = "1.0.0"
3
3
  end
data/regexp_trie.gemspec CHANGED
@@ -25,4 +25,5 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency "rake", "~> 10.0"
26
26
  spec.add_development_dependency "minitest", "~> 5.0"
27
27
  spec.add_development_dependency "minitest-power_assert"
28
+ spec.add_development_dependency "simplecov"
28
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: regexp_trie
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - FUJI Goro (gfx)
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-04-20 00:00:00.000000000 Z
11
+ date: 2016-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  description: Optimized Regexp builder with Trie as a port of Perl's Regexp::Trie
70
84
  email:
71
85
  - gfuji@cpan.org
@@ -109,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
123
  version: '0'
110
124
  requirements: []
111
125
  rubyforge_project:
112
- rubygems_version: 2.4.5.1
126
+ rubygems_version: 2.5.1
113
127
  signing_key:
114
128
  specification_version: 4
115
129
  summary: Optimized Regexp builder with Trie