dropmire 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -22,19 +22,29 @@ module Dropmire
22
22
  @attrs
23
23
  end
24
24
 
25
+ def text
26
+ @text
27
+ end
28
+
25
29
  def parse
26
- parse_methods.each do |method|
27
- self.send method
28
- end
30
+ parse_methods.each { |method| self.send method }
29
31
  end
30
32
 
31
33
  def parse_methods
32
- [ :parse_address, :parse_carrot_string, :date_of_birth, :zipcode,
33
- :license_class, :expiration_date, :parse_license_num ]
34
+ [ :parse_address, :parse_carrot_string, :parse_dates,
35
+ :zipcode, :license_class, :parse_license_num ]
34
36
  end
35
37
 
36
- def address
37
- /\A[%][a-zA-Z]*/.match(@text).to_s
38
+ def parse_address
39
+ addr = address(@text)
40
+ @attrs[:address][:state] = state(addr)
41
+ @attrs[:address][:city] = city(addr)
42
+
43
+ [@attrs[:address][:city], @attrs[:address][:state]]
44
+ end
45
+
46
+ def address(text)
47
+ /\A[%][a-zA-Z\s]*/.match(text).to_s
38
48
  end
39
49
 
40
50
  def state(addr)
@@ -58,14 +68,6 @@ module Dropmire
58
68
  street street_string
59
69
  end
60
70
 
61
- def parse_address
62
- addr = address
63
- @attrs[:address][:state] = state(addr)
64
- @attrs[:address][:city] = city(addr)
65
-
66
- [@attrs[:address][:city], @attrs[:address][:state]]
67
- end
68
-
69
71
  def split_name(name)
70
72
  name.split('$')
71
73
  end
@@ -117,13 +119,17 @@ module Dropmire
117
119
  license_num(id_str)
118
120
  end
119
121
 
120
- def expiration_date
121
- str = /=[0-9]{4}/.match(@text).to_s
122
- @attrs[:expiration_date] = transform_date str[1,4]
122
+ def parse_dates
123
+ str = /=[0-9]*/.match(@text).to_s
124
+ date_of_birth(str)
125
+ expiration_date(str)
123
126
  end
124
127
 
125
- def date_of_birth
126
- str = /=[0-9]*/.match(@text).to_s
128
+ def expiration_date(dob)
129
+ @attrs[:expiration_date] = transform_date(dob[1,4]) + "-#{dob[11,2]}"
130
+ end
131
+
132
+ def date_of_birth(str)
127
133
  dob = str[5,8]
128
134
  year = dob[0,4]
129
135
  month = str[3,2]
@@ -1,3 +1,3 @@
1
1
  module Dropmire
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
data/spec/parser_spec.rb CHANGED
@@ -11,13 +11,20 @@ describe Dropmire::Parser do
11
11
 
12
12
  describe "#address" do
13
13
  it "returns the address section" do
14
- expect(subject.address).to eql "%FLTALLAHASSEE"
14
+ expect(subject.address(subject.instance_variable_get(:@text))).to eql "%FLTALLAHASSEE"
15
+ end
16
+
17
+ context "when city is two words" do
18
+ it "returns the address section" do
19
+ @demo_text2 = """%FLPALM CITY^JACOBSEN$CONNOR$ALAN^6357 SINKOLA DR^ ?;6360101021210193207=1506199306070=?+! 323124522 E 1602 ECCECC00000?"""
20
+ expect(subject.address(@demo_text2)).to eql "%FLPALM CITY"
21
+ end
15
22
  end
16
23
  end
17
24
 
18
25
  describe "#state" do
19
26
  it "returns the correct state" do
20
- addr = subject.address
27
+ addr = subject.address(subject.instance_variable_get(:@text))
21
28
 
22
29
  expect(subject.state(addr)).to eql "FL"
23
30
  end
@@ -25,7 +32,7 @@ describe Dropmire::Parser do
25
32
 
26
33
  describe "#city" do
27
34
  it "returns the correct city" do
28
- addr = subject.address
35
+ addr = subject.address(subject.instance_variable_get(:@text))
29
36
 
30
37
  expect(subject.city(addr)).to eql "Tallahassee"
31
38
  end
@@ -94,7 +101,7 @@ describe Dropmire::Parser do
94
101
 
95
102
  describe "#expiration_date" do
96
103
  it "returns the correct date" do
97
- expect(subject.expiration_date).to eql "2015-06"
104
+ expect(subject.expiration_date("=1506199306070")).to eql "2015-06-07"
98
105
  end
99
106
  end
100
107
 
@@ -107,7 +114,7 @@ describe Dropmire::Parser do
107
114
  describe "#date_of_birth" do
108
115
  context "Florida" do
109
116
  it "returns correct date_of_birth" do
110
- expect(subject.date_of_birth).to eql "1993-06-07"
117
+ expect(subject.date_of_birth("=1506199306070")).to eql "1993-06-07"
111
118
  end
112
119
  end
113
120
  end
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.2
4
+ version: 0.1.3
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-09 00:00:00.000000000 Z
12
+ date: 2014-10-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler