class Podpisy::Postcodes

Public Class Methods

new() click to toggle source
# File lib/podpisy/postcodes.rb, line 8
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

Public Instance Methods

unambiguous(kod, *order) click to toggle source
# File lib/podpisy/postcodes.rb, line 22
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