class Governator::BioPage
Scrapes the biographical page for an individual Governor
Attributes
uri[R]
Public Class Methods
new(uri)
click to toggle source
# File lib/governator/bio_page.rb, line 13 def initialize(uri) @uri = uri @raw = Nokogiri::HTML get_page_contents(uri) check_for_alt_office end
Public Instance Methods
address()
click to toggle source
# File lib/governator/bio_page.rb, line 55 def address @_address ||= address_array.join(' ') end
address_array()
click to toggle source
# File lib/governator/bio_page.rb, line 50 def address_array @_address_array ||= address_paragraph_text(0).delete("\t\n").sub('Address:', '').split(' ') - [' '] end
address_panel()
click to toggle source
# File lib/governator/bio_page.rb, line 46 def address_panel @_address_panel ||= raw.css('address')[1] end
address_paragraph_text(index)
click to toggle source
# File lib/governator/bio_page.rb, line 79 def address_paragraph_text(index) address_panel.css('p')[index]&.text end
alt_address()
click to toggle source
# File lib/governator/bio_page.rb, line 101 def alt_address @alt_address ||= alt_address_array[8..11].join(' ') if alt_office_present? end
alt_address_array()
click to toggle source
# File lib/governator/bio_page.rb, line 91 def alt_address_array return unless alt_office_present? @_alt_address_array ||= alt_address_paragraph_text(0).delete("\t\n").sub('Address:', '').split(' ') - [' '] end
alt_address_panel()
click to toggle source
# File lib/governator/bio_page.rb, line 87 def alt_address_panel @_alt_address_panel ||= raw.css('address')[2] if alt_office_present? end
alt_address_paragraph_text(index)
click to toggle source
# File lib/governator/bio_page.rb, line 131 def alt_address_paragraph_text(index) alt_address_panel.css('p')[index]&.text end
alt_building()
click to toggle source
# File lib/governator/bio_page.rb, line 97 def alt_building @_alt_building ||= alt_address_array[0..7].join(' ') if alt_office_present? end
alt_city()
click to toggle source
# File lib/governator/bio_page.rb, line 109 def alt_city @_alt_city ||= alt_address_paragraph_text(1).delete(',') if alt_office_present? end
alt_fax()
click to toggle source
# File lib/governator/bio_page.rb, line 126 def alt_fax return unless alt_office_present? @_alt_fax ||= alt_address_paragraph_text(5)&.delete("\t\nFax:")&.strip&.sub('/', '-') end
alt_office_present?()
click to toggle source
# File lib/governator/bio_page.rb, line 24 def alt_office_present? @alt_office_present end
alt_office_type()
click to toggle source
# File lib/governator/bio_page.rb, line 135 def alt_office_type return unless alt_office_present? alt_state == 'DC' ? 'dc' : 'district' end
alt_phone()
click to toggle source
# File lib/governator/bio_page.rb, line 121 def alt_phone return unless alt_office_present? @_alt_phone ||= alt_address_paragraph_text(4).delete("\t\nPhone: ").strip.sub('/', '-') end
alt_state()
click to toggle source
# File lib/governator/bio_page.rb, line 113 def alt_state @_alt_state ||= alt_address_paragraph_text(2) if alt_office_present? end
alt_suite()
click to toggle source
# File lib/governator/bio_page.rb, line 105 def alt_suite @alt_suite ||= alt_address_array[13..14].join(' ') if alt_office_present? end
alt_zip()
click to toggle source
# File lib/governator/bio_page.rb, line 117 def alt_zip @_alt_zip ||= alt_address_paragraph_text(3) if alt_office_present? end
check_for_alt_office()
click to toggle source
# File lib/governator/bio_page.rb, line 19 def check_for_alt_office @alt_office_present = raw.css('address')[2].to_s =~ /Phone|Address|Fax/ ? true : false end
city()
click to toggle source
# File lib/governator/bio_page.rb, line 59 def city @_city ||= address_paragraph_text(1).delete(',') end
fax()
click to toggle source
# File lib/governator/bio_page.rb, line 75 def fax @_fax ||= address_paragraph_text(5)&.delete("\t\nFax:")&.strip&.sub('/', '-') end
office_type()
click to toggle source
# File lib/governator/bio_page.rb, line 83 def office_type 'capitol' end
party()
click to toggle source
# File lib/governator/bio_page.rb, line 42 def party @_party ||= party_paragraph.text.delete("\t\n#{nbsp}").sub('Party:', '') end
party_panel()
click to toggle source
# File lib/governator/bio_page.rb, line 32 def party_panel @_party_panel ||= alt_office_present? ? raw.css('address')[3] : raw.css('address')[2] end
party_paragraph()
click to toggle source
# File lib/governator/bio_page.rb, line 36 def party_paragraph @_party_paragraph ||= party_panel.css('p').detect do |p| p.text.include?('Party') end end
phone()
click to toggle source
# File lib/governator/bio_page.rb, line 71 def phone @_phone ||= address_paragraph_text(4)&.delete("\t\nPhone: ")&.strip&.sub('/', '-') end
state()
click to toggle source
# File lib/governator/bio_page.rb, line 63 def state @_state ||= address_paragraph_text(2) end
website()
click to toggle source
# File lib/governator/bio_page.rb, line 28 def website @_website ||= raw.css('.ullist-wrap a').first['href'] end
zip()
click to toggle source
# File lib/governator/bio_page.rb, line 67 def zip @_zip ||= address_paragraph_text(3) end