Class: Parliamentarian::Australia::Victoria

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

Constant Summary collapse

LEGISLATIVE_COUNCIL_URL =
'https://www.parliament.vic.gov.au/images/members/councilmembers.csv'
LEGISLATIVE_ASSEMBLY_URL =
'https://www.parliament.vic.gov.au/images/members/assemblymembers.csv'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(row) ⇒ Victoria

class << self



46
47
48
49
50
51
52
53
# File 'lib/Parliamentarian/Australia/Victoria.rb', line 46

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
  extract_postcode_from_electorate_office_address
end

Class Method Details

.all(legislative_councillors_csv_file_location = nil, legislative_assemblymembers_csv_file_location = nil) ⇒ Object



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

def all(legislative_councillors_csv_file_location = nil, legislative_assemblymembers_csv_file_location = nil)
  @all ||= (legislative_councillors(legislative_councillors_csv_file_location) + legislative_assemblymembers(legislative_assemblymembers_csv_file_location)).flatten
end

.fetch(csv_file_location) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/Parliamentarian/Australia/Victoria.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

.legislative_assemblymembers(csv_file_location = nil) ⇒ Object



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

def legislative_assemblymembers(csv_file_location = nil)
  @legislative_assembly ||= (
    csv_file_location = csv_file_location || LEGISLATIVE_ASSEMBLY_URL
    fetch(csv_file_location).collect{|row| self.new(row)}
  )
end

.legislative_councillors(csv_file_location = nil) ⇒ Object



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

def legislative_councillors(csv_file_location = nil)
  @legislative_council ||= (
    csv_file_location = csv_file_location || LEGISLATIVE_COUNCIL_URL
    fetch(csv_file_location).collect{|row| self.new(row)}
  )
end

Instance Method Details

#first_nameObject



57
# File 'lib/Parliamentarian/Australia/Victoria.rb', line 57

def first_name; preferred_name; end

#firstnameObject

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



56
# File 'lib/Parliamentarian/Australia/Victoria.rb', line 56

def firstname; preferred_name; end

#lastnameObject



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

def lastname; last_name; end

#surnameObject



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

def surname; last_name; end