Class: MyRepresentatives::SA::WebShow
- Inherits:
-
Object
- Object
- MyRepresentatives::SA::WebShow
show all
- Includes:
- Guessable
- Defined in:
- lib/my_representatives/sa/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/sa/web_show.rb', line 6
def document
@document
end
|
#logger ⇒ Object
Returns the value of attribute logger.
6
7
8
|
# File 'lib/my_representatives/sa/web_show.rb', line 6
def logger
@logger
end
|
#url ⇒ Object
Returns the value of attribute url.
6
7
8
|
# File 'lib/my_representatives/sa/web_show.rb', line 6
def url
@url
end
|
Instance Method Details
#electorate_name ⇒ Object
60
61
62
63
64
65
66
|
# File 'lib/my_representatives/sa/web_show.rb', line 60
def electorate_name
begin
@document.at('td.boxedtext:contains("Electorate")').next_element.text
rescue NoMethodError
nil
end
end
|
#email ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/my_representatives/sa/web_show.rb', line 76
def email
begin
regex = /Email(.+?@.+?.sa.gov.au)/
text = @document.text.strip
match = text.match(regex)
if match
match[1]
else
nil
end
rescue NoMethodError
nil
end
end
|
#first_name ⇒ Object
36
37
38
39
40
41
42
|
# File 'lib/my_representatives/sa/web_show.rb', line 36
def first_name
begin
guess_first(formal_name)
rescue NoMethodError
nil
end
end
|
20
21
22
23
24
25
26
|
# File 'lib/my_representatives/sa/web_show.rb', line 20
def formal_name
begin
@document.title.strip.gsub("Profile: ","")
rescue NoMethodError
nil
end
end
|
#homepage_url ⇒ Object
16
17
18
|
# File 'lib/my_representatives/sa/web_show.rb', line 16
def homepage_url
@url
end
|
#image_url ⇒ Object
91
92
93
94
|
# File 'lib/my_representatives/sa/web_show.rb', line 91
def image_url
id = homepage_url.split("=")
"http://www2.parliament.sa.gov.au/FormerMembers/Common/Handler/PersonImage.ashx?PersonId=#{id.last}"
end
|
#last_name ⇒ Object
44
45
46
47
48
49
50
|
# File 'lib/my_representatives/sa/web_show.rb', line 44
def last_name
begin
guess_last(formal_name)
rescue NoMethodError
nil
end
end
|
#party_name ⇒ Object
68
69
70
71
72
73
74
|
# File 'lib/my_representatives/sa/web_show.rb', line 68
def party_name
begin
@document.at('td.boxedtext:contains("Political Party")').next_element.text
rescue NoMethodError
nil
end
end
|
#phone ⇒ Object
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
# File 'lib/my_representatives/sa/web_show.rb', line 96
def phone
begin
phone = @document.at('b:contains("Electorate Telephone:")')
alt_phone = @document.at('b:contains("Telephone:")')
if phone
phone = phone.parent.text
regex = /Electorate Telephone:(08 [0-9]{4} [0-9]{4})/
alt_regex = /Electorate Telephone:([0-9]{4} [0-9]{4})/
match = phone.match(regex)
match_alt = phone.match(alt_regex)
if match
match[1]
elsif match_alt
"08"+match_alt[1]
else
nil
end
elsif alt_phone
phone = alt_phone.parent.text
regex = /Telephone:(08 [0-9]{4} [0-9]{4})/
alt_regex = /Telephone:([0-9]{4} [0-9]{4})/
last_attempt = /Telephone:(1800 [0-9]{3} [0-9]{3})/
match = phone.match(regex)
match_alt = phone.match(alt_regex)
match_last = phone.match(last_attempt)
if match
match[1]
elsif match_alt
"08"+match_alt[1]
elsif match_last
match_last[1]
else
nil
end
else
nil
end
rescue
nil
end
end
|
#preferred_name ⇒ Object
52
53
54
55
56
57
58
|
# File 'lib/my_representatives/sa/web_show.rb', line 52
def preferred_name
begin
guess_preferred(formal_name)
rescue NoMethodError
nil
end
end
|
#title ⇒ Object
28
29
30
31
32
33
34
|
# File 'lib/my_representatives/sa/web_show.rb', line 28
def title
begin
guess_title(formal_name)
rescue NoMethodError
nil
end
end
|