Class: SgPostcode::LongLatConverter
- Inherits:
-
Object
- Object
- SgPostcode::LongLatConverter
- Defined in:
- lib/sg_postcode/converters/long_lat_converter.rb
Instance Attribute Summary collapse
-
#postcodes ⇒ Object
readonly
Returns the value of attribute postcodes.
Instance Method Summary collapse
-
#convert ⇒ Object
Convert an array of SG Postcode.
-
#initialize(postcodes, opts = {}) ⇒ LongLatConverter
constructor
A new instance of LongLatConverter.
-
#place_info(postcode) ⇒ Object
Request info from host for a postcode.
-
#send_geo_request(postcode) ⇒ Object
Send request to host, and return the response.
Constructor Details
#initialize(postcodes, opts = {}) ⇒ LongLatConverter
Returns a new instance of LongLatConverter.
5 6 7 8 |
# File 'lib/sg_postcode/converters/long_lat_converter.rb', line 5 def initialize(postcodes, opts = {}) @postcodes = postcodes opts end |
Instance Attribute Details
#postcodes ⇒ Object (readonly)
Returns the value of attribute postcodes.
3 4 5 |
# File 'lib/sg_postcode/converters/long_lat_converter.rb', line 3 def postcodes @postcodes end |
Instance Method Details
#convert ⇒ Object
Convert an array of SG Postcode
18 19 20 21 22 |
# File 'lib/sg_postcode/converters/long_lat_converter.rb', line 18 def convert postcodes .uniq .map { |postcode| density_of(postcode, place_info(postcode)) } end |
#place_info(postcode) ⇒ Object
Request info from host for a postcode
@params: postcode number [String]
31 32 33 |
# File 'lib/sg_postcode/converters/long_lat_converter.rb', line 31 def place_info(postcode) send_geo_request(postcode).data end |
#send_geo_request(postcode) ⇒ Object
Send request to host, and return the response
SgPostcode::LongLatConverter.send_geo_request(“230000”)
45 46 47 48 49 50 |
# File 'lib/sg_postcode/converters/long_lat_converter.rb', line 45 def send_geo_request(postcode) Response.new( response(postcode), response_type: :json ) end |