governator 0.1.9 → 0.1.10

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: 74a7686c22cba09e8aa50f5d696b063ab79f1720
4
- data.tar.gz: cf8c6c80b7ba5c53ac84ba2841b645f9d156fc52
3
+ metadata.gz: '0786767ccd0fd5582e610a5624efa8637ad61996'
4
+ data.tar.gz: 27c94c6ec91d39c2a4f7db1508fc9175b0bdef26
5
5
  SHA512:
6
- metadata.gz: 8d8dd89e1fbbbb6824ef258143836d045598b67c6212d8a74d0ffea008ee4e4cd0d9403e058799a62129d544002a962bab74a8fc3ab31ef6c2b42ad509d42419
7
- data.tar.gz: 1489ec8eadcedd71e9b0310d13bdbde1e59960eb7e2d70bff6a44e4abb876c3d6448df313fd483f5de150489f9f7bd98e0ddb758275e63a1b61143700b02de56
6
+ metadata.gz: dc01befab8bb1465b9704709ea70df929b028fdb79aed39db6c9eb6fb4879afe5ade43623ddda86de8a5f0455f8c585ab7471cd55f12aea773e1639f3f3bde9e
7
+ data.tar.gz: c3ff56a12367e31f02ed04124fad148bcc2d57845e9dc677a9a610235c9daa9bd07e5dfede666446ee8015dcd9afebba0bbd5f7a1895e3f0d3ba34c4a94f7297
@@ -13,7 +13,7 @@ class Governator
13
13
  end
14
14
 
15
15
  def check_for_alt_office
16
- @alt_office_present = if raw.css('address')[2].to_s.match(/Phone|Address|Fax/)
16
+ @alt_office_present = if raw.css('address')[2].to_s =~ /Phone|Address|Fax/
17
17
  true
18
18
  else
19
19
  false
@@ -52,7 +52,7 @@ class Governator
52
52
 
53
53
  def address_array
54
54
  @_address_array ||=
55
- address_panel.css('p').first.text.delete("\t\n").sub('Address:', '').split(' ') - [' ']
55
+ address_paragraph_text(0).delete("\t\n").sub('Address:', '').split(' ') - [' ']
56
56
  end
57
57
 
58
58
  def address
@@ -60,23 +60,27 @@ class Governator
60
60
  end
61
61
 
62
62
  def city
63
- @_city ||= address_panel.css('p')[1].text.delete(',')
63
+ @_city ||= address_paragraph_text(1).delete(',')
64
64
  end
65
65
 
66
66
  def state
67
- @_state ||= address_panel.css('p')[2]&.text
67
+ @_state ||= address_paragraph_text(2)
68
68
  end
69
69
 
70
70
  def zip
71
- @_zip ||= address_panel.css('p')[3]&.text
71
+ @_zip ||= address_paragraph_text(3)
72
72
  end
73
73
 
74
74
  def phone
75
- @_phone ||= address_panel.css('p')[4].text.delete("\t\nPhone: ").strip.sub('/', '-')
75
+ @_phone ||= address_paragraph_text(4)&.delete("\t\nPhone: ").strip.sub('/', '-')
76
76
  end
77
77
 
78
78
  def fax
79
- @_fax ||= address_panel.css('p')[5]&.text&.delete("\t\nFax:")&.strip&.sub('/', '-')
79
+ @_fax ||= address_paragraph_text(5)&.delete("\t\nFax:")&.strip&.sub('/', '-')
80
+ end
81
+
82
+ def address_paragraph_text(index)
83
+ address_panel.css('p')[index]&.text
80
84
  end
81
85
 
82
86
  def office_type
@@ -90,7 +94,7 @@ class Governator
90
94
  def alt_address_array
91
95
  return unless alt_office_present?
92
96
  @_alt_address_array ||=
93
- alt_address_panel.css('p').first.text.delete("\t\n").sub('Address:', '').split(' ') - [' ']
97
+ alt_address_paragraph_text(0).delete("\t\n").sub('Address:', '').split(' ') - [' ']
94
98
  end
95
99
 
96
100
  def alt_building
@@ -106,25 +110,29 @@ class Governator
106
110
  end
107
111
 
108
112
  def alt_city
109
- @_alt_city ||= alt_address_panel.css('p')[1].text.delete(',') if alt_office_present?
113
+ @_alt_city ||= alt_address_paragraph_text(1).delete(',') if alt_office_present?
110
114
  end
111
115
 
112
116
  def alt_state
113
- @_alt_state ||= alt_address_panel.css('p')[2].text if alt_office_present?
117
+ @_alt_state ||= alt_address_paragraph_text(2) if alt_office_present?
114
118
  end
115
119
 
116
120
  def alt_zip
117
- @_alt_zip ||= alt_address_panel.css('p')[3].text if alt_office_present?
121
+ @_alt_zip ||= alt_address_paragraph_text(3) if alt_office_present?
118
122
  end
119
123
 
120
124
  def alt_phone
121
125
  return unless alt_office_present?
122
- @_alt_phone ||= alt_address_panel.css('p')[4].text.delete("\t\nPhone: ").strip.sub('/', '-')
126
+ @_alt_phone ||= alt_address_paragraph_text(4).delete("\t\nPhone: ").strip.sub('/', '-')
123
127
  end
124
128
 
125
129
  def alt_fax
126
130
  return unless alt_office_present?
127
- @_alt_fax ||= alt_address_panel.css('p')[5]&.text&.delete("\t\nFax:")&.strip&.sub('/', '-')
131
+ @_alt_fax ||= alt_address_paragraph_text(5)&.delete("\t\nFax:")&.strip&.sub('/', '-')
132
+ end
133
+
134
+ def alt_address_paragraph_text(index)
135
+ alt_address_panel.css('p')[index]&.text
128
136
  end
129
137
 
130
138
  def alt_office_type
@@ -20,9 +20,11 @@ class Governator
20
20
  end
21
21
 
22
22
  def facebook
23
- if record && record['facebook_url']
24
- @_facebook ||= record['facebook_url'].sub('https://www.facebook.com/', '')
25
- end
23
+ @_facebook ||= record['facebook_url'].sub('https://www.facebook.com/', '') if facebook_url?
24
+ end
25
+
26
+ def facebook_url?
27
+ record && record['facebook_url']
26
28
  end
27
29
 
28
30
  def photo_url
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Governator
4
+ Office = Struct.new *%i[address city state zip phone fax office_type] do
5
+ def to_s
6
+ [address, city, state, zip, phone, fax].compact.join("\n")
7
+ end
8
+ end
9
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Governator
4
- VERSION = '0.1.9'
4
+ VERSION = '0.1.10'
5
5
  end
data/lib/governator.rb CHANGED
@@ -7,6 +7,7 @@ require 'twitter'
7
7
  require 'governator/bio_page'
8
8
  require 'governator/civil_services'
9
9
  require 'governator/name_parser'
10
+ require 'governator/office'
10
11
  require 'governator/panel'
11
12
  require 'governator/twitter_client'
12
13
  require 'governator/version'
@@ -29,6 +30,7 @@ class Governator
29
30
 
30
31
  governors
31
32
  end
33
+ alias governate! scrape!
32
34
 
33
35
  def governors
34
36
  @_governors ||= []
@@ -85,14 +87,10 @@ class Governator
85
87
  end
86
88
 
87
89
  def to_h
88
- {
89
- photo_url: photo_url,
90
- state_name: state_name,
91
- official_full: official_full,
92
- url: url,
93
- party: party,
94
- office_locations: office_locations
95
- }
90
+ syms = %i[photo_url state_name official_full url party office_locations]
91
+ syms.each_with_object({}) do |sym, hsh|
92
+ hsh[sym] = send(sym)
93
+ end
96
94
  end
97
95
 
98
96
  def inspect
@@ -100,14 +98,18 @@ class Governator
100
98
  end
101
99
 
102
100
  def secondary_office
103
- { address: bio_page.alt_address, city: bio_page.alt_city, state: bio_page.alt_state,
104
- zip: bio_page.alt_zip, phone: bio_page.alt_phone, fax: bio_page.alt_fax,
105
- office_type: bio_page.alt_office_type }
101
+ @_secondary_office ||= office(prefix: :alt_)
106
102
  end
107
103
 
108
104
  def primary_office
109
- { address: bio_page.address, city: bio_page.city, state: bio_page.state, zip: bio_page.zip,
110
- phone: bio_page.phone, fax: bio_page.fax, office_type: bio_page.office_type }
105
+ @_primary_office ||= office
106
+ end
107
+
108
+ def office(prefix: nil)
109
+ syms = %i[address city state zip phone fax office_type]
110
+ syms.each_with_object(Office.new) do |sym, office|
111
+ office[sym] = bio_page.send("#{prefix}#{sym}")
112
+ end
111
113
  end
112
114
 
113
115
  def photo_url
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: governator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - M. Simon Borg
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-06-22 00:00:00.000000000 Z
11
+ date: 2017-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -94,6 +94,7 @@ files:
94
94
  - lib/governator/bio_page.rb
95
95
  - lib/governator/civil_services.rb
96
96
  - lib/governator/name_parser.rb
97
+ - lib/governator/office.rb
97
98
  - lib/governator/page_scraper.rb
98
99
  - lib/governator/panel.rb
99
100
  - lib/governator/twitter_client.rb
@@ -118,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
119
  version: '0'
119
120
  requirements: []
120
121
  rubyforge_project:
121
- rubygems_version: 2.5.1
122
+ rubygems_version: 2.6.11
122
123
  signing_key:
123
124
  specification_version: 4
124
125
  summary: Scraper for data on US Governors