get-your-rep 1.3.1 → 2.0.0

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: 6b65ff3454591d1ede812f534a057153baf8fa42
4
- data.tar.gz: 72af8fb79c5af6203b79dd139be79cb75f779d21
3
+ metadata.gz: 377a9223f6574e5f8585202648f52afcb1ee7e0b
4
+ data.tar.gz: 0220d9f4d752434531457534dc0fff1614f10283
5
5
  SHA512:
6
- metadata.gz: a5daecb7e779110c1bdb7fa16fd96aa258cefe0c4ff8ee2ac7a014fdf4ac5f6eb05299217be4c6e04425b293b46db79fac996875ee2ff05005424b3217b28fd0
7
- data.tar.gz: 3e8b8d9ec37957ac72d76aec2603c89a7a3e53ca808ea76bb745d0d6ffd8d7ccef72935cba67bafc2194d440bb59d4a7860f18d21bea10e1ef36c7d03659937e
6
+ metadata.gz: ebbd293551727d531aa44a6ca1bf23033f058d9731e4c877b2f7c276e4e6281c3cf0d2bcc7b65f5810182cf22b066a0fe80c7fc039c530f827ccc1f3a1ed5324
7
+ data.tar.gz: aa05f88a2ead6bc986c9476179ffc327e8776a08236b3975e007c215d02e59b46cfdd06df36558c2647bf8354041446335f105d627a2e72d6e09ffa5bd92c848
data/lib/get-your-rep.rb CHANGED
@@ -2,6 +2,7 @@
2
2
  require 'httparty'
3
3
  require_relative 'get-your-rep/delegation.rb'
4
4
  require_relative 'get-your-rep/patches.rb'
5
+ require_relative 'get-your-rep/representative.rb'
5
6
 
6
7
  # The GetYourRep class has a collection of class methods that retrieve your elected representatives
7
8
  # from the Google Civic Information API, parse it from JSON, and assemble it into a usable
@@ -79,22 +80,21 @@ class GetYourRep
79
80
  @officials = @response['officials']
80
81
 
81
82
  i = 0
83
+
82
84
  @officials.each do |official|
83
- @delegation[i] = {}
85
+ @delegation[i] = Representative[
86
+ :name, official['name'],
87
+ :office, @response['offices'].first['name'],
88
+ :party, official['party'],
89
+ :phone, official['phones'].first,
90
+ :address_1, official['address'].first['line1'],
91
+ :address_2, official['address'].first['line2'],
92
+ :address_3, "#{official['address'].first['city'].capitalize}, #{official['address'].first['state']} #{official['address'].first['zip']}",
93
+ :email, official['emails'],
94
+ :url, official['urls'].first,
95
+ :photo, official['photoUrl']
96
+ ]
84
97
 
85
- @delegation[i][:name] = official['name']
86
- @delegation[i][:office] = @response['offices'].first['name']
87
- @delegation[i][:party] = official['party']
88
- @delegation[i][:phone] = official['phones'].first
89
- @delegation[i][:address_1] = official['address'].first['line1']
90
- @delegation[i][:address_2] = official['address'].first['line2']
91
- @delegation[i][:address_3] = official['address'].first['line3']
92
- @delegation[i][:address_city] = official['address'].first['city'].capitalize
93
- @delegation[i][:address_state] = official['address'].first['state']
94
- @delegation[i][:address_zip] = official['address'].first['zip']
95
- @delegation[i][:email] = official['emails'] if official['emails']
96
- @delegation[i][:url] = official['urls'].first
97
- @delegation[i][:photo] = official['photoUrl']
98
98
  i += 1
99
99
  end
100
100
  end
@@ -21,42 +21,61 @@ class Delegation < Array
21
21
 
22
22
  # Collects the first names of every rep in the Delegation.
23
23
  def first_names
24
- self.map do |rep|
25
- if (rep[:name].split.count > 3) || (rep[:name].split[-2].downcase == rep[:name].split[-2])
26
- rep[:name].split[0..-3].join(' ')
27
- else
28
- rep[:name].split[0..-2].join(' ')
29
- end
30
- end
24
+ self.map { |rep| rep.first_name }
31
25
  end
32
26
 
33
27
  # Collects the last names of every rep in the Delegation.
34
28
  def last_names
35
- self.map do |rep|
36
- if (rep[:name].split.count > 3) || (rep[:name].split[-2].downcase == rep[:name].split[-2])
37
- rep[:name].split[-2..-1].join(' ')
38
- else
39
- rep[:name].split.last
40
- end
41
- end
29
+ self.map { |rep| rep.last_name }
42
30
  end
43
31
 
44
- # Maps attributes to a simple array for easy printing, iteration, and display. It uses #each rather than #map so it can skip over nil values without mapping them.
32
+ # Maps all rep business cards.
45
33
  def business_cards
46
- card = []
47
- i = 0
48
- self.each do |rep|
49
- card[i] = []
50
- rep.each do |key, value|
51
- next if value.nil?
52
- if key == :facebook || key == :twitter || key == :youtube || key == :googleplus
53
- card[i] << "#{key.to_s.capitalize}: #{value}"
54
- else
55
- card[i] << "#{value}"
56
- end
57
- end
58
- i += 1
59
- end
60
- card
34
+ self.map { |rep| rep.business_card }
35
+ end
36
+
37
+ # Get the [1] index.
38
+ def second
39
+ self[1]
40
+ end
41
+
42
+ # Get the [2] index.
43
+ def third
44
+ self[2]
45
+ end
46
+
47
+ # Get the [3] index.
48
+ def fourth
49
+ self[3]
50
+ end
51
+
52
+ # Get the [4] index.
53
+ def fifth
54
+ self[4]
55
+ end
56
+
57
+ # Get the [5] index.
58
+ def sixth
59
+ self[5]
60
+ end
61
+
62
+ # Get the [6] index.
63
+ def seventh
64
+ self[6]
65
+ end
66
+
67
+ # Get the [7] index.
68
+ def eigth
69
+ self[7]
70
+ end
71
+
72
+ # Get the [8] index.
73
+ def ninth
74
+ self[8]
75
+ end
76
+
77
+ # Get the [9] index.
78
+ def tenth
79
+ self[9]
61
80
  end
62
81
  end
@@ -4,6 +4,11 @@ class Array
4
4
  def to_del
5
5
  Delegation.new(self)
6
6
  end
7
+
8
+ # Converts an Array to a Representative
9
+ def to_rep
10
+ Representative[to_h]
11
+ end
7
12
  end
8
13
 
9
14
  # :nodoc
@@ -13,4 +18,9 @@ class Hash
13
18
  del = Delegation.new
14
19
  del << self
15
20
  end
21
+
22
+ # Converts a Hash to a Representative
23
+ def to_rep
24
+ Representative[self]
25
+ end
16
26
  end
@@ -0,0 +1,189 @@
1
+ # Stores rep info in key/value pairs, and makes values accessible by instance method.
2
+ class Representative < Hash
3
+
4
+ # Strips the first name out of the full name.
5
+ def first_name
6
+ if (name.split.count > 3) || (name.split[-2].downcase == name.split[-2])
7
+ name.split[0..-3].join(' ')
8
+ else
9
+ name.split[0..-2].join(' ')
10
+ end
11
+ end
12
+
13
+ # Strips the surname out of the full name.
14
+ def last_name
15
+ if (name.split.count > 3) || (name.split[-2].downcase == name.split[-2])
16
+ name.split[-2..-1].join(' ')
17
+ else
18
+ name.split.last
19
+ end
20
+ end
21
+
22
+ # Maps attributes to a simple array for easy printing, iteration, and display. It uses #each rather than #map so it can skip over nil values without mapping them.
23
+ def business_card
24
+ card = []
25
+ self.each do |key, value|
26
+ next if value.nil?
27
+ if key == :facebook || key == :twitter || key == :youtube || key == :googleplus
28
+ card << "#{key.to_s.capitalize}: #{value}"
29
+ else
30
+ card << "#{value}"
31
+ end
32
+ end
33
+ card
34
+ end
35
+
36
+ # Get the :name value.
37
+ def name
38
+ @name = self[:name]
39
+ end
40
+
41
+ # Set the :name value.
42
+ def name=(value)
43
+ @name = value
44
+ self[:name] = @name
45
+ end
46
+
47
+ # Get the :office value.
48
+ def office
49
+ @office = self[:office]
50
+ end
51
+
52
+ # Set the :office value.
53
+ def office=(value)
54
+ @office = value
55
+ self[:office] = @office
56
+ end
57
+
58
+ # Get the :party value.
59
+ def party
60
+ @party = self[:party]
61
+ end
62
+
63
+ # Set the :party value.
64
+ def party=(value)
65
+ @party = value
66
+ self[:party] = @party
67
+ end
68
+
69
+ # Get the :phone value.
70
+ def phone
71
+ @phone = self[:phone]
72
+ end
73
+
74
+ # Set the :phone value.
75
+ def phone=(value)
76
+ @phone = value
77
+ self[:phone] = @phone
78
+ end
79
+
80
+ # Get the :address_1 value.
81
+ def address_1
82
+ @address_1 = self[:address_1]
83
+ end
84
+
85
+ # Set the :address_1 value.
86
+ def address_1=(value)
87
+ @address_1 = value
88
+ self[:address_1] = @address_1
89
+ end
90
+
91
+ # Get the :address_2 value.
92
+ def address_2
93
+ @address_2 = self[:address_2]
94
+ end
95
+
96
+ # Set the :address_2 value.
97
+ def address_2=(value)
98
+ @address_2 = value
99
+ self[:address_2] = @address_2
100
+ end
101
+
102
+ # Get the :address_3 value.
103
+ def address_3
104
+ @address_3 = self[:address_3]
105
+ end
106
+
107
+ # Set the :address_3 value.
108
+ def address_3=(value)
109
+ @address_3 = value
110
+ self[:address_3] = @address_3
111
+ end
112
+
113
+ # Get the :email value.
114
+ def email
115
+ @email = self[:email]
116
+ end
117
+
118
+ # Set the :email value.
119
+ def email=(value)
120
+ @email = value
121
+ self[:email] = @email
122
+ end
123
+
124
+ # Get the :url value.
125
+ def url
126
+ @url = self[:url]
127
+ end
128
+
129
+ # Set the :url value.
130
+ def url=(value)
131
+ @url = value
132
+ self[:url] = @url
133
+ end
134
+
135
+ # Get the :photo value.
136
+ def photo
137
+ @photo = self[:photo]
138
+ end
139
+
140
+ # Set the :photo value.
141
+ def photo=(value)
142
+ @photo = value
143
+ self[:photo] = @photo
144
+ end
145
+
146
+ # Get the :twitter value.
147
+ def twitter
148
+ @twitter = self[:twitter]
149
+ end
150
+
151
+ # Set the :twitter value.
152
+ def twitter=(value)
153
+ @twitter = value
154
+ self[:twitter] = @twitter
155
+ end
156
+
157
+ # Get the :facebook value.
158
+ def facebook
159
+ @facebook = self[:facebook]
160
+ end
161
+
162
+ # Set the :facebook value.
163
+ def facebook=(value)
164
+ @facebook = value
165
+ self[:facebook] = @facebook
166
+ end
167
+
168
+ # Get the :youtube value.
169
+ def youtube
170
+ @youtube = self[:youtube]
171
+ end
172
+
173
+ # Set the :youtube value.
174
+ def youtube=(value)
175
+ @youtube = value
176
+ self[:youtube] = @youtube
177
+ end
178
+
179
+ # Get the :googleplus value.
180
+ def googleplus
181
+ @googleplus = self[:googleplus]
182
+ end
183
+
184
+ # Set the :googleplus value.
185
+ def googleplus=(value)
186
+ @googleplus = value
187
+ self[:googleplus] = @googleplus
188
+ end
189
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: get-your-rep
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - msimonborg
@@ -93,8 +93,9 @@ dependencies:
93
93
  - !ruby/object:Gem::Version
94
94
  version: '10'
95
95
  description: Get your rep with Google's Civic Information API using your address and
96
- API key. Check the documentation and README for new search options added in this
97
- version 1.3. This patch fixes some incorrect handling of multi-word surnames.
96
+ API key. Check the documentation and README for new features added in this release.
97
+ There is slight backwards incompatibility with version 1.x in the data structure
98
+ of a rep.
98
99
  email: msimonborg@gmail.com
99
100
  executables: []
100
101
  extensions: []
@@ -103,6 +104,7 @@ files:
103
104
  - lib/get-your-rep.rb
104
105
  - lib/get-your-rep/delegation.rb
105
106
  - lib/get-your-rep/patches.rb
107
+ - lib/get-your-rep/representative.rb
106
108
  homepage: https://github.com/msimonborg/get-your-rep
107
109
  licenses:
108
110
  - MIT