text_extractor 0.1.3 → 0.1.4

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: f7789a07f712aa1892f43c31122ef8313a7f646b
4
- data.tar.gz: dbcf38adc0418a078837f98f77f97b3987e65397
3
+ metadata.gz: 7d29f56c023ab50d2bcf9f40869e78febd4fbbb8
4
+ data.tar.gz: 87da343a092a575b7683bfca3378ed3eeabff820
5
5
  SHA512:
6
- metadata.gz: c60db73cccad682036b86ee0b0ae29168a3d2e2806d0129814f5024c6998ed1dd2e6480510f3936cc38a98658f8ca8a46d27407acaf41ec3b0769687550c08da
7
- data.tar.gz: 1eb622f02aa40b1cdd735bd99ff711986920d1eddf6a121fb8f3c30b55d239b89eada507aaa3e5b44799c0abd167f90bcccb6b6822f1571b57ca92fecdb1e457
6
+ metadata.gz: edcafad5fed934fde4b68b7b22058c600ecdadcbbcf629634285951860740f7a25136de3d133f075bce0a50cdc6bc7265c2b7ff14712ac495885ecc3c5c62741
7
+ data.tar.gz: b09236449430419201b8e9f3a359f10b0933e0d2584d44b2b424137b2f733e6aa35b95172663f85ff4b2fe2cc68bb1af4b80771161a96d92ce205e1afe4faa3b
@@ -20,15 +20,37 @@ class TextExtractor
20
20
  def build_extraction(extracted)
21
21
  case factory
22
22
  when Hash
23
- klass, params = factory.first
24
- klass.new(*extracted.values_at(*params))
23
+ build_extraction_by_hash(extracted)
24
+ when Set
25
+ build_extraction_by_set(extracted)
25
26
  when Class
26
- factory.new(*extracted.values)
27
+ build_extraction_by_class(extracted)
27
28
  else
28
29
  extracted
29
30
  end
30
31
  end
31
32
 
33
+ def build_extraction_by_hash(extracted)
34
+ klass, params = factory.first
35
+ klass.new(*extracted.values_at(*params))
36
+ end
37
+
38
+ def build_extraction_by_set(extracted)
39
+ klass, params = factory.first
40
+ values = params.each_with_object({}) do |param, hash|
41
+ hash[param] = extracted[param]
42
+ end
43
+ klass.new(**values)
44
+ end
45
+
46
+ def build_extraction_by_class(extracted)
47
+ if factory.ancestors.include?(Struct)
48
+ factory.new(*extracted.values)
49
+ else
50
+ factory.new(**extracted)
51
+ end
52
+ end
53
+
32
54
  def match(string, pos = 0)
33
55
  @regexp.match(string, pos)
34
56
  end
@@ -1,5 +1,5 @@
1
1
  class TextExtractor
2
2
  def self.version
3
- '0.1.3'
3
+ '0.1.4'
4
4
  end
5
5
  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.3
4
+ version: 0.1.4
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-16 00:00:00.000000000 Z
11
+ date: 2016-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler