Class: Apidae::Town

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/apidae/town.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.import(json_file) ⇒ Object



3
4
5
6
7
8
9
10
11
12
# File 'app/models/apidae/town.rb', line 3

def self.import(json_file)
  result = true
  towns_json = File.read(json_file)
  towns_hashes = JSON.parse(towns_json, symbolize_names: true)
  towns_hashes.each do |town_data|
    Town.create!(name: town_data[:nom], postal_code: town_data[:codePostal], insee_code: town_data[:code],
                 country: 'fr', apidae_id: town_data[:id])
  end
  result
end

Instance Method Details

#labelObject



14
15
16
# File 'app/models/apidae/town.rb', line 14

def label
  "#{name} (#{postal_code})"
end