Class: MySociety::MapIt::Postcode

Inherits:
Object
  • Object
show all
Includes:
LocalAuthorityFinder, UriToHash
Defined in:
lib/my_society/map_it.rb

Constant Summary

Constants included from LocalAuthorityFinder

LocalAuthorityFinder::COUNTY_TYPE_CODES, LocalAuthorityFinder::COUNTY_WARD_TYPE_CODES, LocalAuthorityFinder::DISTRICT_TYPE_CODES, LocalAuthorityFinder::PARISH_TYPE_CODES, LocalAuthorityFinder::UNITARY_TYPE_CODES, LocalAuthorityFinder::WARD_TYPE_CODES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from UriToHash

#to_hash

Methods included from LocalAuthorityFinder

#county, #county_ward, #detect, #district, #local_authority, #parish, #two_tier?, #unitary, #ward

Constructor Details

#initialize(postcode) ⇒ Postcode

Returns a new instance of Postcode.



175
176
177
# File 'lib/my_society/map_it.rb', line 175

def initialize postcode
  self.postcode = postcode
end

Instance Attribute Details

#postcodeObject

Returns the value of attribute postcode.



172
173
174
# File 'lib/my_society/map_it.rb', line 172

def postcode
  @postcode
end

Instance Method Details

#easting_northingObject



192
193
194
195
196
197
198
199
200
# File 'lib/my_society/map_it.rb', line 192

def easting_northing
  h = to_hash.dup
  if h['coordsyst'] == "G"
    coordsyst = Point::SYSTEM_BRITISH_NATIONAL_GRID
  else h['coordsyst'] == "I"
    coordsyst = Point::SYSTEM_IRISH_NATIONAL_GRID
  end
  Point.new h['northing'], h['easting'], coordsyst
end

#normalised_postcodeObject



179
180
181
# File 'lib/my_society/map_it.rb', line 179

def normalised_postcode
  postcode.upcase.gsub /\s+/, ''
end

#to_pointObject



187
188
189
190
# File 'lib/my_society/map_it.rb', line 187

def to_point
  h = to_hash.dup
  Point.new h['wgs84_lat'], h['wgs84_lon'], Point::SYSTEM_WGS84
end

#uriObject



183
184
185
# File 'lib/my_society/map_it.rb', line 183

def uri
  "#{MySociety::MapIt.base_url}/postcode/#{normalised_postcode}"
end