Class: MyRepresentatives::NSW::WebShow
- Inherits:
-
Object
- Object
- MyRepresentatives::NSW::WebShow
show all
- Includes:
- Guessable
- Defined in:
- lib/my_representatives/nsw/web_show.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Guessable
#guess_first, #guess_gender, #guess_last, #guess_preferred, #guess_title
Constructor Details
#initialize(url) ⇒ WebShow
Returns a new instance of WebShow.
Instance Attribute Details
#document ⇒ Object
Returns the value of attribute document.
6
7
8
|
# File 'lib/my_representatives/nsw/web_show.rb', line 6
def document
@document
end
|
#logger ⇒ Object
Returns the value of attribute logger.
6
7
8
|
# File 'lib/my_representatives/nsw/web_show.rb', line 6
def logger
@logger
end
|
#url ⇒ Object
Returns the value of attribute url.
6
7
8
|
# File 'lib/my_representatives/nsw/web_show.rb', line 6
def url
@url
end
|
Instance Method Details
#electorate_name ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/my_representatives/nsw/web_show.rb', line 87
def electorate_name
begin
electorate = @document.css(".office").css("div.title")[0].text.strip
if electorate.include?("Electorate Office")
electorate.gsub!(" Electorate Office","")
else
"All NSW"
end
rescue NoMethodError
nil
end
end
|
#email ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/my_representatives/nsw/web_show.rb', line 74
def email
begin
email = @document.css(".contact_office").at('a:contains("@parliament.nsw.gov.au")')
if email.is_a?(Array)
email.first.attr('href').strip.gsub("mailto:","")
else
email.attr('href').strip.gsub("mailto:","")
end
rescue NoMethodError
nil
end
end
|
#first_name ⇒ Object
28
29
30
31
32
33
34
|
# File 'lib/my_representatives/nsw/web_show.rb', line 28
def first_name
begin
guess_first(formal_name)
rescue NoMethodError
nil
end
end
|
20
21
22
23
24
25
26
|
# File 'lib/my_representatives/nsw/web_show.rb', line 20
def formal_name
begin
unformatted_name.split(",")[0].titleize
rescue NoMethodError
nil
end
end
|
#homepage_url ⇒ Object
16
17
18
|
# File 'lib/my_representatives/nsw/web_show.rb', line 16
def homepage_url
@url
end
|
#image_url ⇒ Object
100
101
102
103
104
105
106
|
# File 'lib/my_representatives/nsw/web_show.rb', line 100
def image_url
begin
"https://www.parliament.nsw.gov.au" + @document.css("div.img_position").css("img").attr('src').value.strip
rescue NoMethodError
nil
end
end
|
#last_name ⇒ Object
44
45
46
47
48
49
50
|
# File 'lib/my_representatives/nsw/web_show.rb', line 44
def last_name
begin
guess_last(formal_name)
rescue NoMethodError
nil
end
end
|
#party_name ⇒ Object
52
53
54
55
56
57
|
# File 'lib/my_representatives/nsw/web_show.rb', line 52
def party_name
begin
rescue NoMethodError
nil
end
end
|
#phone ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/my_representatives/nsw/web_show.rb', line 59
def phone
begin
phone = @document.css(".contact_office").css("th.label_cell")
index = phone.find_index { |p| p.text == "P" }
if index
phone[index].next_element.text
else
nil
end
rescue NoMethodError
nil
end
end
|
#preferred_name ⇒ Object
36
37
38
39
40
41
42
|
# File 'lib/my_representatives/nsw/web_show.rb', line 36
def preferred_name
begin
guess_preferred(formal_name)
rescue NoMethodError
nil
end
end
|