Class: PlZipCodes
- Inherits:
-
Object
- Object
- PlZipCodes
- Defined in:
- lib/pl-zip-codes/pl_zip_codes.rb
Constant Summary collapse
- CSV_FILENAME =
'lib.csv'
- CSV_SEPARATOR =
';'
Class Method Summary collapse
Class Method Details
.data ⇒ Object
34 35 36 37 |
# File 'lib/pl-zip-codes/pl_zip_codes.rb', line 34 def data load_data @data end |
.find(code = nil) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/pl-zip-codes/pl_zip_codes.rb', line 25 def find(code = nil) load_data if block_given? @data.find_all {|k| yield(k) } else @data.find_all {|k| k[:code] == code.to_s } end end |
.load_data ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/pl-zip-codes/pl_zip_codes.rb', line 9 def load_data if @data.nil? @data = [] CSV.foreach(File.("../#{CSV_FILENAME}", __FILE__), col_sep: CSV_SEPARATOR) do |csv_obj| @data << { code: csv_obj[1], city: csv_obj[2] || csv_obj[3].capitalize.match(/(\S+).+/)[1], province: csv_obj[3], street: csv_obj[5], region: csv_obj[4].capitalize, notes: csv_obj[6] } end end end |