class Parliamentarian::Australia::Federal
Constants
- HOUSE_OF_REPRESENTATIVES_URL
- SENATE_URL
Public Class Methods
all(senators_csv_file_location = nil, members_csv_file_location = nil)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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
Also aliased as: house_of_representatives
new(row)
click to toggle source
# 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
senators(csv_file_location = nil)
click to toggle source
# 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
Also aliased as: senate
Public Instance Methods
firstname()
click to toggle source
For consistency with Australia::Victoria
and vice-versa…
# File lib/Parliamentarian/Australia/Federal.rb, line 58 def firstname; first_name; end
last_name()
click to toggle source
# File lib/Parliamentarian/Australia/Federal.rb, line 60 def last_name; surname; end
lastname()
click to toggle source
# File lib/Parliamentarian/Australia/Federal.rb, line 59 def lastname; surname; end
member?()
click to toggle source
# File lib/Parliamentarian/Australia/Federal.rb, line 72 def member? !senator? end
postcode()
click to toggle source
# File lib/Parliamentarian/Australia/Federal.rb, line 62 def postcode @electorate_postcode end
senator?()
click to toggle source
predicate methods
# File lib/Parliamentarian/Australia/Federal.rb, line 68 def senator? salutation == 'Senator' end
Private Instance Methods
attr_name(header)
click to toggle source
# File lib/Parliamentarian/Australia/Federal.rb, line 78 def attr_name(header) header.underscore end
synthesize_email_address()
click to toggle source
# File lib/Parliamentarian/Australia/Federal.rb, line 82 def synthesize_email_address self.class.send(:attr_accessor, 'email') self.email = ( if senator? "senator.#{surname.downcase}@aph.gov.au" else "#{first_name}.#{surname}.MP@aph.gov.au" end ) end