Class: Parliamentarian::Australia::Federal

Inherits:
Object
  • Object
show all
Defined in:
lib/Parliamentarian/Australia/Federal.rb

Constant Summary collapse

SENATE_URL =
'https://www.aph.gov.au/~/media/03%20Senators%20and%20Members/Address%20Labels%20and%20CSV%20files/Senators/allsenel.csv?la=en'
HOUSE_OF_REPRESENTATIVES_URL =
'https://www.aph.gov.au/~/media/03%20Senators%20and%20Members/Address%20Labels%20and%20CSV%20files/SurnameRepsCSV.csv?la=en'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(row) ⇒ Federal

class << self



48
49
50
51
52
53
54
55
# File 'lib/Parliamentarian/Australia/Federal.rb', line 48

def initialize(row)
  row.keys.each do |header|
    attr_name = self.attr_name(header)
    self.class.send(:attr_accessor, attr_name)
    self.send("#{attr_name}=", row[header])
  end
  synthesize_email_address
end

Class Method Details

.all(senators_csv_file_location = nil, members_csv_file_location = nil) ⇒ Object



26
27
28
# File 'lib/Parliamentarian/Australia/Federal.rb', line 26

def all(senators_csv_file_location = nil, members_csv_file_location = nil)
  @all ||= (senators(senators_csv_file_location) + house_of_representatives(members_csv_file_location)).flatten
end

.fetch(csv_file_location) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/Parliamentarian/Australia/Federal.rb', line 17

def fetch(csv_file_location)
  raw_csv = if ['http', 'https'].include?(URI.parse(csv_file_location).scheme)
    URI.open(csv_file_location)
  else
    File.read(csv_file_location)
  end
  SimpleCSV.read(raw_csv, headers: true)
end

.members(csv_file_location = nil) ⇒ Object Also known as: house_of_representatives



38
39
40
41
42
43
# File 'lib/Parliamentarian/Australia/Federal.rb', line 38

def members(csv_file_location = nil)
  @members ||= (
    csv_file_location = csv_file_location || HOUSE_OF_REPRESENTATIVES_URL
    fetch(csv_file_location).collect{|row| self.new(row)}
  )
end

.senators(csv_file_location = nil) ⇒ Object Also known as: senate



30
31
32
33
34
35
# File 'lib/Parliamentarian/Australia/Federal.rb', line 30

def senators(csv_file_location = nil)
  @senators ||= (
    csv_file_location = csv_file_location || SENATE_URL
    fetch(csv_file_location).collect{|row| self.new(row)}
  )
end

Instance Method Details

#firstnameObject

For consistency with Australia::Victoria and vice-versa…



58
# File 'lib/Parliamentarian/Australia/Federal.rb', line 58

def firstname; first_name; end

#last_nameObject



60
# File 'lib/Parliamentarian/Australia/Federal.rb', line 60

def last_name; surname; end

#lastnameObject



59
# File 'lib/Parliamentarian/Australia/Federal.rb', line 59

def lastname; surname; end

#member?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/Parliamentarian/Australia/Federal.rb', line 72

def member?
  !senator?
end

#postcodeObject



62
63
64
# File 'lib/Parliamentarian/Australia/Federal.rb', line 62

def postcode
  @electorate_postcode
end

#senator?Boolean

predicate methods

Returns:

  • (Boolean)


68
69
70
# File 'lib/Parliamentarian/Australia/Federal.rb', line 68

def senator?
  salutation == 'Senator'
end