Class: Governator
- Inherits:
-
Object
- Object
- Governator
- Defined in:
- lib/governator.rb,
lib/governator/panel.rb,
lib/governator/version.rb,
lib/governator/bio_page.rb,
lib/governator/name_parser.rb,
lib/governator/page_scraper.rb,
lib/governator/civil_services.rb,
lib/governator/twitter_client.rb
Overview
Governator.scrape! governors = Governor.governors
Defined Under Namespace
Classes: BioPage, CivilServices, NameParser, PageScraper, Panel, TwitterClient
Constant Summary collapse
- BASE_URI =
'https://www.nga.org'
- CONN =
Faraday.new(url: BASE_URI)
- VERSION =
'0.1.8'
Class Attribute Summary collapse
-
.use_twitter ⇒ Object
Returns the value of attribute use_twitter.
Instance Attribute Summary collapse
-
#bio_page ⇒ Object
readonly
<– End class methods.
-
#first ⇒ Object
readonly
<– End class methods.
-
#last ⇒ Object
readonly
<– End class methods.
-
#middle ⇒ Object
readonly
<– End class methods.
-
#nickname ⇒ Object
readonly
<– End class methods.
-
#office_locations ⇒ Object
readonly
<– End class methods.
-
#official_full ⇒ Object
readonly
<– End class methods.
-
#panel ⇒ Object
readonly
<– End class methods.
-
#party ⇒ Object
readonly
<– End class methods.
-
#state_name ⇒ Object
readonly
<– End class methods.
-
#suffix ⇒ Object
readonly
<– End class methods.
-
#twitter ⇒ Object
readonly
<– End class methods.
-
#url ⇒ Object
readonly
<– End class methods.
Class Method Summary collapse
- .config {|_self| ... } ⇒ Object
- .governors ⇒ Object
- .scrape! ⇒ Object
- .to_json ⇒ Object (also: serialize)
- .twitter(&block) ⇒ Object
- .twitter_client ⇒ Object
Instance Method Summary collapse
- #contact_form ⇒ Object
- #facebook ⇒ Object
-
#initialize(panel) ⇒ Governator
constructor
A new instance of Governator.
- #inspect ⇒ Object
- #photo_url ⇒ Object
- #primary_office ⇒ Object
- #secondary_office ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(panel) ⇒ Governator
Returns a new instance of Governator.
83 84 85 |
# File 'lib/governator.rb', line 83 def initialize(panel) @panel = panel end |
Class Attribute Details
.use_twitter ⇒ Object
Returns the value of attribute use_twitter.
21 22 23 |
# File 'lib/governator.rb', line 21 def use_twitter @use_twitter end |
Instance Attribute Details
#bio_page ⇒ Object (readonly)
<– End class methods
79 80 81 |
# File 'lib/governator.rb', line 79 def bio_page @bio_page end |
#first ⇒ Object (readonly)
<– End class methods
79 80 81 |
# File 'lib/governator.rb', line 79 def first @first end |
#last ⇒ Object (readonly)
<– End class methods
79 80 81 |
# File 'lib/governator.rb', line 79 def last @last end |
#middle ⇒ Object (readonly)
<– End class methods
79 80 81 |
# File 'lib/governator.rb', line 79 def middle @middle end |
#nickname ⇒ Object (readonly)
<– End class methods
79 80 81 |
# File 'lib/governator.rb', line 79 def nickname @nickname end |
#office_locations ⇒ Object (readonly)
<– End class methods
79 80 81 |
# File 'lib/governator.rb', line 79 def office_locations @office_locations end |
#official_full ⇒ Object (readonly)
<– End class methods
79 80 81 |
# File 'lib/governator.rb', line 79 def official_full @official_full end |
#panel ⇒ Object (readonly)
<– End class methods
79 80 81 |
# File 'lib/governator.rb', line 79 def panel @panel end |
#party ⇒ Object (readonly)
<– End class methods
79 80 81 |
# File 'lib/governator.rb', line 79 def party @party end |
#state_name ⇒ Object (readonly)
<– End class methods
79 80 81 |
# File 'lib/governator.rb', line 79 def state_name @state_name end |
#suffix ⇒ Object (readonly)
<– End class methods
79 80 81 |
# File 'lib/governator.rb', line 79 def suffix @suffix end |
#twitter ⇒ Object (readonly)
<– End class methods
79 80 81 |
# File 'lib/governator.rb', line 79 def twitter @twitter end |
#url ⇒ Object (readonly)
<– End class methods
79 80 81 |
# File 'lib/governator.rb', line 79 def url @url end |
Class Method Details
.config {|_self| ... } ⇒ Object
42 43 44 |
# File 'lib/governator.rb', line 42 def config yield self end |
.governors ⇒ Object
33 34 35 |
# File 'lib/governator.rb', line 33 def governors @_governors ||= [] end |
.scrape! ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/governator.rb', line 23 def scrape! governors.clear panels.each do |panel| governor = create(panel) puts "Scraped #{governor.official_full} of #{governor.state_name}" end governors end |
.to_json ⇒ Object Also known as: serialize
37 38 39 |
# File 'lib/governator.rb', line 37 def to_json governors.map(&:to_h) end |
.twitter(&block) ⇒ Object
46 47 48 |
# File 'lib/governator.rb', line 46 def twitter(&block) TwitterClient.config(&block) end |
.twitter_client ⇒ Object
50 51 52 |
# File 'lib/governator.rb', line 50 def twitter_client TwitterClient.client end |
Instance Method Details
#contact_form ⇒ Object
121 122 123 |
# File 'lib/governator.rb', line 121 def contact_form civil_services.contact_form end |
#facebook ⇒ Object
117 118 119 |
# File 'lib/governator.rb', line 117 def facebook civil_services.facebook end |
#inspect ⇒ Object
98 99 100 |
# File 'lib/governator.rb', line 98 def inspect "#<Governator #{official_full}>" end |
#photo_url ⇒ Object
113 114 115 |
# File 'lib/governator.rb', line 113 def photo_url civil_services.photo_url || BASE_URI + panel.image end |
#primary_office ⇒ Object
108 109 110 111 |
# File 'lib/governator.rb', line 108 def primary_office { address: bio_page.address, city: bio_page.city, state: bio_page.state, zip: bio_page.zip, phone: bio_page.phone, fax: bio_page.fax, office_type: bio_page.office_type } end |
#secondary_office ⇒ Object
102 103 104 105 106 |
# File 'lib/governator.rb', line 102 def secondary_office { address: bio_page.alt_address, city: bio_page.alt_city, state: bio_page.alt_state, zip: bio_page.alt_zip, phone: bio_page.alt_phone, fax: bio_page.alt_fax, office_type: bio_page.alt_office_type } end |
#to_h ⇒ Object
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/governator.rb', line 87 def to_h { photo_url: photo_url, state_name: state_name, official_full: official_full, url: url, party: party, office_locations: office_locations } end |