Class: DataAnon::Utils::GeojsonParser

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path) ⇒ GeojsonParser

Returns a new instance of GeojsonParser.



28
29
30
# File 'lib/utils/geojson_parser.rb', line 28

def initialize file_path
  @places = File.read(file_path).split(/\n/)
end

Class Method Details

.address(file_path) ⇒ Object



8
9
10
# File 'lib/utils/geojson_parser.rb', line 8

def self.address file_path
  self.new(file_path).parse 'address'
end

.city(file_path) ⇒ Object



20
21
22
# File 'lib/utils/geojson_parser.rb', line 20

def self.city file_path
  self.new(file_path).parse 'city'
end

.country(file_path) ⇒ Object



24
25
26
# File 'lib/utils/geojson_parser.rb', line 24

def self.country file_path
  self.new(file_path).parse 'country'
end

.province(file_path) ⇒ Object



16
17
18
# File 'lib/utils/geojson_parser.rb', line 16

def self.province file_path
  self.new(file_path).parse 'province'
end

.zipcode(file_path) ⇒ Object



12
13
14
# File 'lib/utils/geojson_parser.rb', line 12

def self.zipcode file_path
  self.new(file_path).parse 'postcode'
end

Instance Method Details

#parse(property) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/utils/geojson_parser.rb', line 32

def parse property
  result_list = []
  @places.each do |loc|
    geom = RGeo::GeoJSON.decode(loc, :json_parser => :json)
    result_list.push(geom[property])
  end
  result_list
end