Sha256: 6cdb423ac86cd41fffa0366744fe6d9f413539a2ede18cd1ea4ee85949c45939
Contents?: true
Size: 742 Bytes
Versions: 7
Compression:
Stored size: 742 Bytes
Contents
# coding: utf-8 require 'set' module Podpisy class Postcodes @@format = {m:"%s", p: "Powiat %s", w: "Województwo %s"} def initialize fn = File.expand_path('kody.csv', File.dirname(__FILE__)) @kody = {} CSV.foreach(fn, headers: true, col_sep: ',') do |row| x = @kody[row['kod']] x = {m:Set.new, p:Set.new, w:Set.new} unless x x[:m] << row['miejscowosc'] x[:p] << row['powiat'] x[:w] << row['wojewodztwo'] @kody[row['kod']] = x end end def unambiguous(kod, *order) x = @kody[kod] return '' unless x order.each do |at| next if x[at].length > 1 return @@format[at] % x[at].first end '' end end end
Version data entries
7 entries across 7 versions & 1 rubygems