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 +4 -4
- data/lib/governator/bio_page.rb +21 -13
- data/lib/governator/civil_services.rb +5 -3
- data/lib/governator/office.rb +9 -0
- data/lib/governator/version.rb +1 -1
- data/lib/governator.rb +15 -13
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0786767ccd0fd5582e610a5624efa8637ad61996'
|
4
|
+
data.tar.gz: 27c94c6ec91d39c2a4f7db1508fc9175b0bdef26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc01befab8bb1465b9704709ea70df929b028fdb79aed39db6c9eb6fb4879afe5ade43623ddda86de8a5f0455f8c585ab7471cd55f12aea773e1639f3f3bde9e
|
7
|
+
data.tar.gz: c3ff56a12367e31f02ed04124fad148bcc2d57845e9dc677a9a610235c9daa9bd07e5dfede666446ee8015dcd9afebba0bbd5f7a1895e3f0d3ba34c4a94f7297
|
data/lib/governator/bio_page.rb
CHANGED
@@ -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
|
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
|
-
|
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 ||=
|
63
|
+
@_city ||= address_paragraph_text(1).delete(',')
|
64
64
|
end
|
65
65
|
|
66
66
|
def state
|
67
|
-
@_state ||=
|
67
|
+
@_state ||= address_paragraph_text(2)
|
68
68
|
end
|
69
69
|
|
70
70
|
def zip
|
71
|
-
@_zip ||=
|
71
|
+
@_zip ||= address_paragraph_text(3)
|
72
72
|
end
|
73
73
|
|
74
74
|
def phone
|
75
|
-
@_phone ||=
|
75
|
+
@_phone ||= address_paragraph_text(4)&.delete("\t\nPhone: ").strip.sub('/', '-')
|
76
76
|
end
|
77
77
|
|
78
78
|
def fax
|
79
|
-
@_fax ||=
|
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
|
-
|
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 ||=
|
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 ||=
|
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 ||=
|
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 ||=
|
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 ||=
|
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
|
-
|
24
|
-
|
25
|
-
|
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
|
data/lib/governator/version.rb
CHANGED
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
|
-
|
90
|
-
|
91
|
-
|
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
|
-
|
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
|
-
|
110
|
-
|
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.
|
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-
|
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.
|
122
|
+
rubygems_version: 2.6.11
|
122
123
|
signing_key:
|
123
124
|
specification_version: 4
|
124
125
|
summary: Scraper for data on US Governors
|