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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 80ea0027acddf0b1b3cd96a78737c6e990159a71
4
- data.tar.gz: 4938b707b639b5efde6013e2c06f1c04a57567a6
3
+ metadata.gz: 9d014b8016f17ef8f54362a7992b196938ccbeab
4
+ data.tar.gz: 5336569aeed786019f4f6dc631d7828a3abecabb
5
5
  SHA512:
6
- metadata.gz: a9d49fa0d38752dbe50969db22489740000ecce854c4e1105e8dd6be0b6a24328f799c6d3594e9a7a3fcab3c7d6f96512ca233030b20bf35461227bbd4351efd
7
- data.tar.gz: 1281833781015336ae886392e07d884ed82787cdba4a5d2eb57f2f1740c5df40ab95d3de88ed38be73034879025c9be2998f62119479fbee86e41a59aeb5960a
6
+ metadata.gz: f69c8ed922dc2c8fa7d6b7da2eb8b252848990d2d7fd205d73f9daebe8288e8980ecb3efbbd5efef33cb5b86c645193297bebdc7a9a623ef140880a248ac2651
7
+ data.tar.gz: 6d3f326791048807c3ddb344bd78ae0395e26c1271cd1f1af781b3ed45a3a4c3d956f6a9ef4014f40ba2a374b51a3231baa9a90b3e454c809f5615d5085087d9
@@ -1,5 +1,5 @@
1
1
  class TextExtractor
2
2
  def self.version
3
- '0.1.0'
3
+ '0.1.1'
4
4
  end
5
5
  end
@@ -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.map! { |s| s.gsub(prefix.to_s, '') } if prefix =~ /\A\s*\z/
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.0
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 00:00:00.000000000 Z
11
+ date: 2016-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler