Class: Edgar::ZipAddress

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/edgar/zip_address.rb

Overview

zip - address correspondence table

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Object) get_record(line) (private)

get csv into array



35
36
37
38
# File 'app/models/edgar/zip_address.rb', line 35

def get_record(line)
  a = line.split(',')
  a.map{|data| data.gsub(/^"/, '').gsub(/"$/, '')}
end

+ (Object) load

Load JP's ken_all.csv from stdin.

'zip' code is not treated as uniq so that reloading results in duplicated records. In order to refresh to the latest zip-address data, please executes 'delete_all' before loading.

example:

$ cd test/dummy
$ gunzip -c ../../db/ken_all.csv.gz | nkf -Sw | rails runner Edgar::ZipAddress.load


18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/models/edgar/zip_address.rb', line 18

def load
  print "start: ", Time.now, "\n"
  while STDIN.gets do
    a = get_record($_)
    if !self.find_by_zip(a[2]) then
      self.create(
        :zip        => a[2],
        :prefecture => a[6],
        :city       => a[7],
        :town       => a[8])
    end
  end
  print "end: ", Time.now, "\n"
end

Instance Method Details

- (Object) name



41
42
43
# File 'app/models/edgar/zip_address.rb', line 41

def name
  [zip, prefecture, city, town].join(' ')
end