text_extractor 0.1.0 → 0.1.1
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/version.rb +1 -1
- data/lib/text_extractor.rb +14 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d014b8016f17ef8f54362a7992b196938ccbeab
|
4
|
+
data.tar.gz: 5336569aeed786019f4f6dc631d7828a3abecabb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f69c8ed922dc2c8fa7d6b7da2eb8b252848990d2d7fd205d73f9daebe8288e8980ecb3efbbd5efef33cb5b86c645193297bebdc7a9a623ef140880a248ac2651
|
7
|
+
data.tar.gz: 6d3f326791048807c3ddb344bd78ae0395e26c1271cd1f1af781b3ed45a3a4c3d956f6a9ef4014f40ba2a374b51a3231baa9a90b3e454c809f5615d5085087d9
|
data/lib/text_extractor.rb
CHANGED
@@ -65,17 +65,28 @@ class TextExtractor
|
|
65
65
|
value(id, re) { |val| IPAddr.new(val) }
|
66
66
|
end
|
67
67
|
|
68
|
-
def strip_record(regexp)
|
68
|
+
def strip_record(regexp, strip: nil)
|
69
69
|
lines = regexp.source.lines
|
70
70
|
prefix = lines.last
|
71
|
-
lines
|
71
|
+
strip_record_by_line(lines, prefix, strip)
|
72
72
|
Regexp.new(lines.join.strip, regexp.options)
|
73
73
|
end
|
74
74
|
|
75
|
+
def strip_record_by_line(lines, prefix, strip)
|
76
|
+
return unless prefix =~ /\A\s*\z/
|
77
|
+
|
78
|
+
lines.map! { |s| s.gsub(prefix.to_s, '') }
|
79
|
+
case strip
|
80
|
+
when :left then lines.map! { |s| "\\s*#{s.lstrip}" }
|
81
|
+
when :right then lines.map! { |s| "#{s.rstrip}\\s*" }
|
82
|
+
when :both then lines.map! { |s| "\\s*#{s.strip}\\s*" }
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
75
86
|
def record(klass = Record, **kwargs, &block)
|
76
87
|
raise "#{self.class}.record requires a block" unless block
|
77
88
|
@current_record_values = []
|
78
|
-
regexp = strip_record(instance_exec(&block))
|
89
|
+
regexp = strip_record(instance_exec(&block), strip: kwargs.delete(:strip))
|
79
90
|
kwargs[:values] = @current_record_values
|
80
91
|
@records << klass.new(regexp, **kwargs)
|
81
92
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: text_extractor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Miller
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|