Class: Governator::BioPage
- Inherits:
-
PageScraper
- Object
- PageScraper
- Governator::BioPage
- Defined in:
- lib/governator/bio_page.rb
Instance Attribute Summary collapse
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Attributes inherited from PageScraper
Instance Method Summary collapse
- #address ⇒ Object
- #address_array ⇒ Object
- #address_panel ⇒ Object
- #alt_address ⇒ Object
- #alt_address_array ⇒ Object
- #alt_address_panel ⇒ Object
- #alt_building ⇒ Object
- #alt_city ⇒ Object
- #alt_fax ⇒ Object
- #alt_office_present? ⇒ Boolean
- #alt_office_type ⇒ Object
- #alt_phone ⇒ Object
- #alt_state ⇒ Object
- #alt_suite ⇒ Object
- #alt_zip ⇒ Object
- #check_for_alt_office ⇒ Object
- #city ⇒ Object
- #fax ⇒ Object
-
#initialize(uri) ⇒ BioPage
constructor
A new instance of BioPage.
- #office_type ⇒ Object
- #party ⇒ Object
- #party_panel ⇒ Object
- #party_paragraph ⇒ Object
- #phone ⇒ Object
- #state ⇒ Object
- #website ⇒ Object
- #zip ⇒ Object
Methods inherited from PageScraper
Constructor Details
#initialize(uri) ⇒ BioPage
Returns a new instance of BioPage.
9 10 11 12 13 |
# File 'lib/governator/bio_page.rb', line 9 def initialize(uri) @uri = uri @raw = Nokogiri::HTML(CONN.get(uri).body) check_for_alt_office end |
Instance Attribute Details
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
7 8 9 |
# File 'lib/governator/bio_page.rb', line 7 def uri @uri end |
Instance Method Details
#address ⇒ Object
58 59 60 |
# File 'lib/governator/bio_page.rb', line 58 def address @_address ||= address_array.join(' ') end |
#address_array ⇒ Object
53 54 55 56 |
# File 'lib/governator/bio_page.rb', line 53 def address_array @_address_array ||= address_panel.css('p').first.text.delete("\t\n").sub('Address:', '').split(' ') - [' '] end |
#address_panel ⇒ Object
49 50 51 |
# File 'lib/governator/bio_page.rb', line 49 def address_panel @_address_panel ||= raw.css('address')[1] end |
#alt_address ⇒ Object
100 101 102 |
# File 'lib/governator/bio_page.rb', line 100 def alt_address @alt_address ||= alt_address_array[8..11].join(' ') if alt_office_present? end |
#alt_address_array ⇒ Object
90 91 92 93 94 |
# File 'lib/governator/bio_page.rb', line 90 def alt_address_array return unless alt_office_present? @_alt_address_array ||= alt_address_panel.css('p').first.text.delete("\t\n").sub('Address:', '').split(' ') - [' '] end |
#alt_address_panel ⇒ Object
86 87 88 |
# File 'lib/governator/bio_page.rb', line 86 def alt_address_panel @_alt_address_panel ||= raw.css('address')[2] if alt_office_present? end |
#alt_building ⇒ Object
96 97 98 |
# File 'lib/governator/bio_page.rb', line 96 def alt_building @_alt_building ||= alt_address_array[0..7].join(' ') if alt_office_present? end |
#alt_city ⇒ Object
108 109 110 |
# File 'lib/governator/bio_page.rb', line 108 def alt_city @_alt_city ||= alt_address_panel.css('p')[1].text.delete(',') if alt_office_present? end |
#alt_fax ⇒ Object
125 126 127 128 |
# File 'lib/governator/bio_page.rb', line 125 def alt_fax return unless alt_office_present? @_alt_fax ||= alt_address_panel.css('p')[5]&.text&.delete("\t\nFax:")&.strip&.sub('/', '-') end |
#alt_office_present? ⇒ Boolean
23 24 25 |
# File 'lib/governator/bio_page.rb', line 23 def alt_office_present? @alt_office_present end |
#alt_office_type ⇒ Object
130 131 132 133 |
# File 'lib/governator/bio_page.rb', line 130 def alt_office_type return unless alt_office_present? alt_state == 'DC' ? 'dc' : 'district' end |
#alt_phone ⇒ Object
120 121 122 123 |
# File 'lib/governator/bio_page.rb', line 120 def alt_phone return unless alt_office_present? @_alt_phone ||= alt_address_panel.css('p')[4].text.delete("\t\nPhone: ").strip.sub('/', '-') end |
#alt_state ⇒ Object
112 113 114 |
# File 'lib/governator/bio_page.rb', line 112 def alt_state @_alt_state ||= alt_address_panel.css('p')[2].text if alt_office_present? end |
#alt_suite ⇒ Object
104 105 106 |
# File 'lib/governator/bio_page.rb', line 104 def alt_suite @alt_suite ||= alt_address_array[13..14].join(' ') if alt_office_present? end |
#alt_zip ⇒ Object
116 117 118 |
# File 'lib/governator/bio_page.rb', line 116 def alt_zip @_alt_zip ||= alt_address_panel.css('p')[3].text if alt_office_present? end |
#check_for_alt_office ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/governator/bio_page.rb', line 15 def check_for_alt_office @alt_office_present = if raw.css('address')[2].to_s.match?(/Phone|Address|Fax/) true else false end end |
#city ⇒ Object
62 63 64 |
# File 'lib/governator/bio_page.rb', line 62 def city @_city ||= address_panel.css('p')[1].text.delete(',') end |
#fax ⇒ Object
78 79 80 |
# File 'lib/governator/bio_page.rb', line 78 def fax @_fax ||= address_panel.css('p')[5]&.text&.delete("\t\nFax:")&.strip&.sub('/', '-') end |
#office_type ⇒ Object
82 83 84 |
# File 'lib/governator/bio_page.rb', line 82 def office_type 'capitol' end |
#party ⇒ Object
45 46 47 |
# File 'lib/governator/bio_page.rb', line 45 def party @_party ||= party_paragraph.text.delete("\t\n#{nbsp}").sub('Party:', '') end |
#party_panel ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/governator/bio_page.rb', line 31 def party_panel @_party_panel ||= if alt_office_present? raw.css('address')[3] else raw.css('address')[2] end end |
#party_paragraph ⇒ Object
39 40 41 42 43 |
# File 'lib/governator/bio_page.rb', line 39 def party_paragraph @_party_paragraph ||= party_panel.css('p').detect do |p| p.text.include?('Party') end end |
#phone ⇒ Object
74 75 76 |
# File 'lib/governator/bio_page.rb', line 74 def phone @_phone ||= address_panel.css('p')[4].text.delete("\t\nPhone: ").strip.sub('/', '-') end |
#state ⇒ Object
66 67 68 |
# File 'lib/governator/bio_page.rb', line 66 def state @_state ||= address_panel.css('p')[2]&.text end |
#website ⇒ Object
27 28 29 |
# File 'lib/governator/bio_page.rb', line 27 def website @_website ||= raw.css('.ullist-wrap a').first['href'] end |
#zip ⇒ Object
70 71 72 |
# File 'lib/governator/bio_page.rb', line 70 def zip @_zip ||= address_panel.css('p')[3]&.text end |