Class: MyRepresentatives::ACT::WebIndexRow

Inherits:
Object
  • Object
show all
Defined in:
lib/my_representatives/act/web_index_row.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document) ⇒ WebIndexRow

Returns a new instance of WebIndexRow.



6
7
8
9
10
# File 'lib/my_representatives/act/web_index_row.rb', line 6

def initialize(document)
  raise MyRepresentatives::NokogiriDocumentExpectedError unless document && document.is_a?(Nokogiri::XML::Element)
  @document = document
  raise MyRepresentatives::NokogiriDocumentPropertiesError unless test_document_for_validity
end

Instance Attribute Details

#documentObject

Returns the value of attribute document.



4
5
6
# File 'lib/my_representatives/act/web_index_row.rb', line 4

def document
  @document
end

Instance Method Details

#addressObject



61
62
63
# File 'lib/my_representatives/act/web_index_row.rb', line 61

def address
  nil
end

#electorate_nameObject



27
28
29
30
31
32
# File 'lib/my_representatives/act/web_index_row.rb', line 27

def electorate_name
  begin
    @document.css("td")[2].text
  rescue
  end
end

#emailObject



51
52
53
54
55
56
57
58
59
# File 'lib/my_representatives/act/web_index_row.rb', line 51

def email
  begin
    text = @document.css("td")[4].text
    regex = /^(.+?@.+?.gov.au)/
    regex.match(text)[1].strip
  rescue
    nil
  end
end

#first_nameObject



12
13
14
15
16
17
18
# File 'lib/my_representatives/act/web_index_row.rb', line 12

def first_name
  begin
    @document.css("a")[0].text.split(",")[1]
  rescue
    nil
  end
end

#homepage_urlObject



65
66
67
68
69
70
71
# File 'lib/my_representatives/act/web_index_row.rb', line 65

def homepage_url
  begin
    @document.css("a")[0].attr("href")
  rescue
    nil
  end
end

#last_nameObject



20
21
22
23
24
25
# File 'lib/my_representatives/act/web_index_row.rb', line 20

def last_name
  begin
    @document.css("a")[0].text.split(",")[0]
  rescue
  end
end

#party_nameObject



34
35
36
37
38
39
# File 'lib/my_representatives/act/web_index_row.rb', line 34

def party_name
  begin
    @document.css("td")[3].text
  rescue
  end
end

#phoneObject



41
42
43
44
45
46
47
48
49
# File 'lib/my_representatives/act/web_index_row.rb', line 41

def phone
  begin
    text = @document.css("td")[4].text
    regex = /Ph:(.+?)$/
    regex.match(text)[1].strip
  rescue
    nil
  end
end