Module: MySociety::MapIt::LocalAuthorityFinder

Included in:
Point, Postcode
Defined in:
lib/my_society/map_it.rb

Constant Summary collapse

LOCAL_AUTHORITY_TYPE_CODES =
%w(
  DIS MTD UTA LBO CTY LGD COI
).map { |c| c.freeze }.freeze

Instance Method Summary collapse

Instance Method Details

#local_authorityObject



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/my_society/map_it.rb', line 25

def local_authority
  local_authority_info = to_point.to_hash.values.sort_by { |a|
    LOCAL_AUTHORITY_TYPE_CODES.index(a['type']) || -1
  }.detect do |la|
	  LOCAL_AUTHORITY_TYPE_CODES.include? la['type']
	end

  return if local_authority_info.nil?

  LocalAuthority.new local_authority_info
rescue
  nil
end