Class: Governator

Inherits:
Object
  • Object
show all
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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_twitterObject

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_pageObject (readonly)

<– End class methods


79
80
81
# File 'lib/governator.rb', line 79

def bio_page
  @bio_page
end

#firstObject (readonly)

<– End class methods


79
80
81
# File 'lib/governator.rb', line 79

def first
  @first
end

#lastObject (readonly)

<– End class methods


79
80
81
# File 'lib/governator.rb', line 79

def last
  @last
end

#middleObject (readonly)

<– End class methods


79
80
81
# File 'lib/governator.rb', line 79

def middle
  @middle
end

#nicknameObject (readonly)

<– End class methods


79
80
81
# File 'lib/governator.rb', line 79

def nickname
  @nickname
end

#office_locationsObject (readonly)

<– End class methods


79
80
81
# File 'lib/governator.rb', line 79

def office_locations
  @office_locations
end

#official_fullObject (readonly)

<– End class methods


79
80
81
# File 'lib/governator.rb', line 79

def official_full
  @official_full
end

#panelObject (readonly)

<– End class methods


79
80
81
# File 'lib/governator.rb', line 79

def panel
  @panel
end

#partyObject (readonly)

<– End class methods


79
80
81
# File 'lib/governator.rb', line 79

def party
  @party
end

#state_nameObject (readonly)

<– End class methods


79
80
81
# File 'lib/governator.rb', line 79

def state_name
  @state_name
end

#suffixObject (readonly)

<– End class methods


79
80
81
# File 'lib/governator.rb', line 79

def suffix
  @suffix
end

#twitterObject (readonly)

<– End class methods


79
80
81
# File 'lib/governator.rb', line 79

def twitter
  @twitter
end

#urlObject (readonly)

<– End class methods


79
80
81
# File 'lib/governator.rb', line 79

def url
  @url
end

Class Method Details

.config {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (Governator)

    the object that the method was called on


42
43
44
# File 'lib/governator.rb', line 42

def config
  yield self
end

.governorsObject


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_jsonObject 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_clientObject


50
51
52
# File 'lib/governator.rb', line 50

def twitter_client
  TwitterClient.client
end

Instance Method Details

#contact_formObject


121
122
123
# File 'lib/governator.rb', line 121

def contact_form
  civil_services.contact_form
end

#facebookObject


117
118
119
# File 'lib/governator.rb', line 117

def facebook
  civil_services.facebook
end

#inspectObject


98
99
100
# File 'lib/governator.rb', line 98

def inspect
  "#<Governator #{official_full}>"
end

#photo_urlObject


113
114
115
# File 'lib/governator.rb', line 113

def photo_url
  civil_services.photo_url || BASE_URI + panel.image
end

#primary_officeObject


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_officeObject


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_hObject


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