Class: LocalAuthority::LocalAuthority

Inherits:
Object
  • Object
show all
Defined in:
lib/local_authority.rb

Constant Summary collapse

DB_FILE =
File.join File.dirname(__FILE__), '..', 'db', 'local_authorities.csv'
DB =
CSV.new File.read(DB_FILE), :headers => :first_row

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ LocalAuthority

Returns a new instance of LocalAuthority.



30
31
32
# File 'lib/local_authority.rb', line 30

def initialize attributes
  self.attributes = attributes
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



27
28
29
# File 'lib/local_authority.rb', line 27

def attributes
  @attributes
end

Class Method Details

.allObject



10
11
12
# File 'lib/local_authority.rb', line 10

def self.all
  @all ||= DB.map { |row| new row.to_hash }
end

.find_by_map_it_id(id) ⇒ Object



14
15
16
17
18
# File 'lib/local_authority.rb', line 14

def self.find_by_map_it_id id
  all.detect { |la|
    la.map_it_id =~ /\/#{id}$/
  }
end

.find_by_postcode(postcode) ⇒ Object



20
21
22
23
24
25
# File 'lib/local_authority.rb', line 20

def self.find_by_postcode postcode
  p = MySociety::MapIt::Postcode.new postcode
  la = p.local_authority
  return if la.nil?
  find_by_map_it_id la.id
end

Instance Method Details

#addressObject



46
47
48
# File 'lib/local_authority.rb', line 46

def address
  attributes['Address']
end

#map_it_idObject



50
51
52
# File 'lib/local_authority.rb', line 50

def map_it_id
  attributes['MapIt ID']
end

#nameObject



38
39
40
# File 'lib/local_authority.rb', line 38

def name
  attributes['Name']
end

#phone_numberObject



42
43
44
# File 'lib/local_authority.rb', line 42

def phone_number
  attributes['Phone Number']
end

#websiteObject



34
35
36
# File 'lib/local_authority.rb', line 34

def website
  attributes['Website']
end