Class: MyRepresentatives::Commonwealth::WebShow
- Inherits:
-
Object
- Object
- MyRepresentatives::Commonwealth::WebShow
- Defined in:
- lib/my_representatives/commonwealth/web_show.rb
Instance Attribute Summary collapse
-
#document ⇒ Object
Returns the value of attribute document.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #electorate_name ⇒ Object
- #email ⇒ Object
- #formal_name ⇒ Object
- #homepage_url ⇒ Object
- #image_url ⇒ Object
-
#initialize(url) ⇒ WebShow
constructor
A new instance of WebShow.
- #party_name ⇒ Object
- #phone ⇒ Object
- #state_name ⇒ Object
Constructor Details
#initialize(url) ⇒ WebShow
Returns a new instance of WebShow.
7 8 9 10 11 12 13 |
# File 'lib/my_representatives/commonwealth/web_show.rb', line 7 def initialize(url) @logger = Logger.new(STDOUT) raise MyRepresentatives::InvalidURLError unless url && url.is_a?(String) @url = url fetch_document raise MyRepresentatives::NokogiriDocumentPropertiesError unless test_document_for_validity end |
Instance Attribute Details
#document ⇒ Object
Returns the value of attribute document.
5 6 7 |
# File 'lib/my_representatives/commonwealth/web_show.rb', line 5 def document @document end |
#logger ⇒ Object
Returns the value of attribute logger.
5 6 7 |
# File 'lib/my_representatives/commonwealth/web_show.rb', line 5 def logger @logger end |
#url ⇒ Object
Returns the value of attribute url.
5 6 7 |
# File 'lib/my_representatives/commonwealth/web_show.rb', line 5 def url @url end |
Instance Method Details
#electorate_name ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/my_representatives/commonwealth/web_show.rb', line 51 def electorate_name begin @document.css(".medium-7").css("h3").text.split(",")[0].strip.gsub("Member for ","").gsub("Senator for ","").gsub(/\s{2,}/,"") rescue NoMethodError nil end end |
#email ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/my_representatives/commonwealth/web_show.rb', line 43 def email begin @document.css("#panel31").at('dt:contains("Email")').next_element.text.strip rescue NoMethodError nil end end |
#formal_name ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/my_representatives/commonwealth/web_show.rb', line 19 def formal_name begin @document.css("h1").text.strip rescue NoMethodError nil end end |
#homepage_url ⇒ Object
15 16 17 |
# File 'lib/my_representatives/commonwealth/web_show.rb', line 15 def homepage_url @url end |
#image_url ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/my_representatives/commonwealth/web_show.rb', line 67 def image_url begin @document.css(".medium-3").css("img").attr('src').value.strip rescue NoMethodError nil end end |
#party_name ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/my_representatives/commonwealth/web_show.rb', line 27 def party_name begin @document.css(".medium-7").at('dt:contains("Party")').next_element.text.strip rescue NoMethodError nil end end |
#phone ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/my_representatives/commonwealth/web_show.rb', line 35 def phone begin @document.css("#panel11").at('dt:contains("Telephone")').next_element.text.strip rescue NoMethodError nil end end |
#state_name ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/my_representatives/commonwealth/web_show.rb', line 59 def state_name begin @document.css(".medium-7").css("h3").text.split(",")[1].strip.gsub("Member for ","").gsub("Senator for ","").gsub(/\s{2,}/,"") rescue NoMethodError nil end end |