Sha256: 98141a859e02a0e2a4dc61db0474e73a1999fd69b4714081c8ef5f138a60dff7

Contents?: true

Size: 610 Bytes

Versions: 2

Compression:

Stored size: 610 Bytes

Contents

class INE::Places::PlacesCollection
  include Singleton

  def self.records
    @records ||= CSV.read("#{INE::Places::ROOT}/data/places.csv", headers: true, encoding: 'utf-8').map do |raw_data|
                   build_from_raw_data(raw_data)
                 end.sort_by(&:slug)
  end

  def self.build_from_raw_data(raw_data)
    INE::Places::Place.new({
      id: raw_data[0], name: raw_data[2],
      slug: raw_data[3], province_id: raw_data[1],
      lon: raw_data[6], lat: raw_data[7],
      province: INE::Places::Province.find(raw_data[1])
    })
  end
  private_class_method :build_from_raw_data

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ine-places-0.6.1 lib/ine/places/places_collection.rb
ine-places-0.6.0 lib/ine/places/places_collection.rb