Class: MyRepresentatives::Commonwealth::WebShow

Inherits:
Object
  • Object
show all
Defined in:
lib/my_representatives/commonwealth/web_show.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#documentObject

Returns the value of attribute document.



5
6
7
# File 'lib/my_representatives/commonwealth/web_show.rb', line 5

def document
  @document
end

#loggerObject

Returns the value of attribute logger.



5
6
7
# File 'lib/my_representatives/commonwealth/web_show.rb', line 5

def logger
  @logger
end

#urlObject

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_nameObject



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

#emailObject



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_nameObject



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_urlObject



15
16
17
# File 'lib/my_representatives/commonwealth/web_show.rb', line 15

def homepage_url
  @url
end

#image_urlObject



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_nameObject



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

#phoneObject



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_nameObject



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