Class: Podpisy::Postcodes
- Inherits:
-
Object
- Object
- Podpisy::Postcodes
- Defined in:
- lib/podpisy/postcodes.rb
Constant Summary collapse
- @@format =
{m:"%s", p: "Powiat %s", w: "Województwo %s"}
Instance Method Summary collapse
-
#initialize ⇒ Postcodes
constructor
A new instance of Postcodes.
- #unambiguous(kod, *order) ⇒ Object
Constructor Details
#initialize ⇒ Postcodes
Returns a new instance of Postcodes.
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/podpisy/postcodes.rb', line 8 def initialize fn = File.('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 |
Instance Method Details
#unambiguous(kod, *order) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# 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 |