dropmire 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,94 +8,43 @@ module Dropmire
8
8
 
9
9
  @attrs = p.attrs
10
10
  end
11
-
12
- # naive method approach
13
- def address
14
- { street: street, city: city, state: state, zipcode: zipcode }
15
- end
16
-
17
- def street
18
- attrs[:address][:street]
19
- end
20
-
21
- def city
22
- attrs[:address][:city]
23
- end
24
-
25
- def state
26
- attrs[:address][:state]
27
- end
28
-
29
- def zipcode
30
- attrs[:address][:zipcode]
31
- end
32
-
33
- def names
34
- { first: first_name, middle: middle_name, last: last_name }
35
- end
36
-
37
- def first_name
38
- attrs[:name][:first]
39
- end
40
-
41
- def middle_name
42
- attrs[:name][:middle]
43
- end
44
-
45
- def last_name
46
- attrs[:name][:last]
47
- end
48
-
49
- def drivers_license_number
50
- attrs[:license_num]
51
- end
52
-
53
- def drivers_license_iin
54
- attrs[:iin]
55
- end
56
-
57
- def drivers_license_class
58
- attrs[:license_class]
59
- end
60
-
61
- def drivers_license_expiration_date
62
- attrs[:expiration_date]
63
- end
64
-
65
- def date_of_birth
66
- attrs[:date_of_birth]
11
+
12
+ def method_missing(method, *args, &block)
13
+ is_attr = attrs.fetch(method, nil)
14
+ if is_attr.nil? && !(dl_id_values.include?(method))
15
+ super
16
+ else
17
+ key = find_key_from_method(method)
18
+ attrs[key]
19
+ end
67
20
  end
68
21
 
69
- # For meta attr methods later...
70
- #
71
- # def method_missing(method, *args, &block)
72
- # if addr_lookup method.to_s
73
-
74
- # else
75
- # super
76
- # end
77
- # end
78
-
79
22
  private
80
23
 
81
24
  def attrs
82
25
  @attrs
83
26
  end
84
27
 
85
- # def attr_lookup(attr)
86
- # if attrs.has_key? attr
87
- # elsif address_vars
88
- # elsif name_vars
89
- # else
90
- # end
91
- # end
28
+ def dl_id_values
29
+ [:drivers_license_expiration_date, :drivers_license_iin,
30
+ :drivers_license_number]
31
+ end
92
32
 
93
- # def address_vars
94
- # %w(street city state zipcode)
95
- # end
33
+ def find_key_from_method(method)
34
+ case method.to_s
35
+ when 'drivers_license_expiration_date'
36
+ :expiration_date
37
+ when 'drivers_license_iin'
38
+ :iin
39
+ when 'drivers_license_number'
40
+ :license_num
41
+ else
42
+ method
43
+ end
44
+ end
96
45
 
97
- # def name_vars
98
- # %w(first middle last first_name middle_name last_name)
99
- # end
46
+ def drivers_license_attrs
47
+ %w(expiration_date iin )
48
+ end
100
49
  end
101
50
  end
@@ -15,7 +15,7 @@ module Dropmire
15
15
  # Returns the Hash of results from the string.
16
16
  def initialize(text, options = {})
17
17
  @text = text
18
- @attrs = {:address=>{}} # empty hash for the parsed values
18
+ @attrs = {}
19
19
  end
20
20
 
21
21
  def attrs
@@ -37,10 +37,10 @@ module Dropmire
37
37
 
38
38
  def parse_address
39
39
  addr = address(@text)
40
- @attrs[:address][:state] = state(addr)
41
- @attrs[:address][:city] = city(addr)
40
+ @attrs[:state] = state(addr)
41
+ @attrs[:city] = city(addr)
42
42
 
43
- [@attrs[:address][:city], @attrs[:address][:state]]
43
+ [@attrs[:city], @attrs[:state]]
44
44
  end
45
45
 
46
46
  def address(text)
@@ -56,14 +56,14 @@ module Dropmire
56
56
  addr[3..l].capitalize
57
57
  end
58
58
 
59
- def carrot_string
60
- str = /\^(.*)\^/.match(@text).to_s
59
+ def carrot_string(text)
60
+ str = /\^(.*)\^/.match(text).to_s
61
61
  len = str.length-2
62
62
  str[1..len].split('^')
63
63
  end
64
64
 
65
65
  def parse_carrot_string
66
- name_string, street_string = carrot_string
66
+ name_string, street_string = carrot_string(@text)
67
67
  names split_name(name_string)
68
68
  street street_string
69
69
  end
@@ -73,11 +73,18 @@ module Dropmire
73
73
  end
74
74
 
75
75
  def names(names)
76
- @attrs[:name] = {
77
- first: names[1].capitalize,
78
- last: names[0].capitalize,
79
- middle: names[2].capitalize
80
- }
76
+ @attrs[:first_name] = names[1].capitalize
77
+ @attrs[:last_name] = names[0].capitalize
78
+ @attrs[:middle_name] = capitalize_or_nil(names[2])
79
+
80
+ [@attrs[:first_name], @attrs[:middle_name], @attrs[:last_name]]
81
+ end
82
+
83
+ # Capitalizes and returns @name if not nil, returns nil otherwise.
84
+ def capitalize_or_nil(name)
85
+ unless name.nil?
86
+ name.capitalize
87
+ end
81
88
  end
82
89
 
83
90
  def street(street)
@@ -86,13 +93,13 @@ module Dropmire
86
93
  ary.each do |s|
87
94
  str << s.capitalize
88
95
  end
89
- @attrs[:address][:street] = str.join(' ')
96
+ @attrs[:street] = str.join(' ')
90
97
  end
91
98
 
92
99
  def zipcode
93
100
  str = /![\s]*[0-9]*/.match(@text).to_s
94
101
  zip = str[1..(str.length)].strip
95
- @attrs[:address][:zipcode] = zip[0,5]
102
+ @attrs[:zipcode] = zip[0,5]
96
103
  end
97
104
 
98
105
  def license_class
@@ -1,3 +1,3 @@
1
1
  module Dropmire
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -68,7 +68,7 @@ describe Dropmire::Identity do
68
68
 
69
69
  describe "#drivers_license_expiration_date" do
70
70
  it "returns correct value" do
71
- expect(subject.drivers_license_expiration_date).to eql "2015-06"
71
+ expect(subject.drivers_license_expiration_date).to eql "2015-06-07"
72
72
  end
73
73
  end
74
74
 
data/spec/parser_spec.rb CHANGED
@@ -47,14 +47,26 @@ describe Dropmire::Parser do
47
47
  describe "#carrot_string" do
48
48
  it "returns the correct array" do
49
49
  carrot_arr = ["JACOBSEN$CONNOR$ALAN", "6357 SINKOLA DR"]
50
- expect(subject.carrot_string).to eql carrot_arr
50
+ @demo_text = """%FLPALM CITY^JACOBSEN$CONNOR$ALAN^6357 SINKOLA DR^ ?;6360101021210193207=1506199306070=?+! 323124522 E 1602 ECCECC00000?"""
51
+ expect(subject.carrot_string(@demo_text)).to eql carrot_arr
51
52
  end
52
53
  end
53
54
 
54
55
  describe "#names" do
55
56
  it "returns the correct array of strings" do
56
- name_hash = {first: "Connor", middle: "Alan", last: "Jacobsen"}
57
- expect(subject.names(%w(JACOBSEN CONNOR ALAN))).to eql name_hash
57
+ name_arr = %w(Connor Alan Jacobsen)
58
+ expect(subject.names(%w(JACOBSEN CONNOR ALAN))).to eql name_arr
59
+ end
60
+
61
+ context "when middle name not present" do
62
+ it "returns the correct hash" do
63
+ @demo_text = """%FLPALM CITY^JACOBSEN$CONNOR$^6357 SINKOLA DR^ ?;6360101021210193207=1506199306070=?+! 323124522 E 1602 ECCECC00000?"""
64
+ carrot_arr = subject.carrot_string(@demo_text)
65
+ name_string = carrot_arr.first
66
+ name_arr = subject.split_name(name_string)
67
+ val = ["Connor", nil, "Jacobsen"]
68
+ expect(subject.names(name_arr)).to eql val
69
+ end
58
70
  end
59
71
  end
60
72
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dropmire
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-10-26 00:00:00.000000000 Z
12
+ date: 2014-11-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler