text_extractor 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/text_extractor/record.rb +12 -2
- data/lib/text_extractor/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c189f0b5ec9e1038d1861be7917451115f06980
|
4
|
+
data.tar.gz: 2817759a04f289b9aea17e559591420f69d74bd2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ff6af6d8e7158e3ee1301e00190ce6865d2d9783510374e0252393837597f4a95dfdee2f5f9b58e634f88753d789ea69d866aa018fd46e2520946c20ba02c98
|
7
|
+
data.tar.gz: 280b8271a4c6b99afd426324fc463c55366d658014bd2e07137ea34ff0511462e5fd687abd435822f667f56dad44fa1acc914162e4ab2e282e446ad88e20d3f7
|
@@ -1,9 +1,11 @@
|
|
1
|
+
require_relative 'directives'
|
2
|
+
|
1
3
|
class TextExtractor
|
2
4
|
class Record
|
3
5
|
attr_reader :regexp, :factory, :values
|
4
6
|
|
5
|
-
def initialize(regexp, factory: nil, values: [], fill: [])
|
6
|
-
@regexp = regexp
|
7
|
+
def initialize(regexp, factory: nil, values: [], fill: [], directives: true)
|
8
|
+
@regexp = expand_regexp(regexp, directives)
|
7
9
|
@factory = factory
|
8
10
|
@constructor = FactoryAnalyzer.new(factory).to_proc
|
9
11
|
@values = values.map { |val| [val.id, val] }.to_h
|
@@ -23,6 +25,14 @@ class TextExtractor
|
|
23
25
|
@constructor.call(extracted)
|
24
26
|
end
|
25
27
|
|
28
|
+
def expand_regexp(regexp, directives)
|
29
|
+
if directives
|
30
|
+
TextExtractor.expand_directives(regexp)
|
31
|
+
else
|
32
|
+
regexp
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
26
36
|
def match(string, pos = 0)
|
27
37
|
@regexp.match(string, pos)
|
28
38
|
end
|