pl-zip-codes 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+ require 'csv'
3
+
4
+ class PlZipCodes
5
+ CSV_FILENAME = 'lib.csv'
6
+ CSV_SEPARATOR = ';'
7
+
8
+ class << self
9
+ def load_data
10
+ if @data.nil?
11
+ @data = []
12
+ CSV.foreach(File.expand_path("../#{CSV_FILENAME}", __FILE__), col_sep: CSV_SEPARATOR) do |csv_obj|
13
+ @data << {
14
+ code: csv_obj[1],
15
+ city: csv_obj[2] || csv_obj[3].capitalize.match(/(\S+).+/)[1],
16
+ province: csv_obj[3].capitalize,
17
+ street: csv_obj[5],
18
+ region: csv_obj[4],
19
+ notes: csv_obj[6]
20
+ }
21
+ end
22
+ end
23
+ end
24
+
25
+ def find(code = nil)
26
+ load_data
27
+ if block_given?
28
+ @data.find_all {|k| yield(k) }
29
+ else
30
+ @data.find_all {|k| k[:code] == code.to_s }
31
+ end
32
+ end
33
+
34
+ def data
35
+ load_data
36
+ @data
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,2 @@
1
+ # encoding: utf-8
2
+ require 'pl-zip-codes/pl_zip_codes'
@@ -0,0 +1,64 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "pl-zip-codes"
8
+ s.version = "0.1.5"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Ernest Bursa"]
12
+ s.date = "2013-02-24"
13
+ s.description = "Simple zip codes database for Poland"
14
+ s.email = "ernest@bzdury.pl"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "lib/pl-zip-codes.rb",
28
+ "lib/pl-zip-codes/lib.csv",
29
+ "lib/pl-zip-codes/pl_zip_codes.rb",
30
+ "pl-zip-codes.gemspec",
31
+ "test/helper.rb",
32
+ "test/test_pl_zip_codes.rb"
33
+ ]
34
+ s.homepage = "http://github.com/swistaczek/pl-zip-codes"
35
+ s.licenses = ["MIT"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = "1.8.24"
38
+ s.summary = "Simple zip codes database for Poland"
39
+
40
+ if s.respond_to? :specification_version then
41
+ s.specification_version = 3
42
+
43
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
45
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
46
+ s.add_development_dependency(%q<bundler>, ["~> 1.2.3"])
47
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
48
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
49
+ else
50
+ s.add_dependency(%q<shoulda>, [">= 0"])
51
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
52
+ s.add_dependency(%q<bundler>, ["~> 1.2.3"])
53
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
54
+ s.add_dependency(%q<simplecov>, [">= 0"])
55
+ end
56
+ else
57
+ s.add_dependency(%q<shoulda>, [">= 0"])
58
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
59
+ s.add_dependency(%q<bundler>, ["~> 1.2.3"])
60
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
61
+ s.add_dependency(%q<simplecov>, [">= 0"])
62
+ end
63
+ end
64
+
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'pl-zip-codes'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+ require 'helper'
3
+
4
+ class TestPlZipCodes < Test::Unit::TestCase
5
+ context "a zipcode for street Jaskiniowa and Wielkopolskie region" do
6
+ setup do
7
+ @poznan_code = PlZipCodes.find {|x| x[:street] == "Jaskiniowa" and x[:region] == "Wielkopolskie" }
8
+ end
9
+
10
+ should "return array with one result" do
11
+ assert_equal 1, @poznan_code.size
12
+ end
13
+
14
+ should "return array with hash with city in keys" do
15
+ assert_equal true, @poznan_code.map(&:keys)[0].include?(:city)
16
+ end
17
+
18
+ should "return array with hash with code in keys" do
19
+ assert_equal true, @poznan_code.map(&:keys)[0].include?(:code)
20
+ end
21
+
22
+ should "return array with hash with province in keys" do
23
+ assert_equal true, @poznan_code.map(&:keys)[0].include?(:province)
24
+ end
25
+
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pl-zip-codes
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.5
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ernest Bursa
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: shoulda
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rdoc
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '3.12'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '3.12'
46
+ - !ruby/object:Gem::Dependency
47
+ name: bundler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 1.2.3
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.2.3
62
+ - !ruby/object:Gem::Dependency
63
+ name: jeweler
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 1.8.4
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 1.8.4
78
+ - !ruby/object:Gem::Dependency
79
+ name: simplecov
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ description: Simple zip codes database for Poland
95
+ email: ernest@bzdury.pl
96
+ executables: []
97
+ extensions: []
98
+ extra_rdoc_files:
99
+ - LICENSE.txt
100
+ - README.rdoc
101
+ files:
102
+ - .document
103
+ - Gemfile
104
+ - Gemfile.lock
105
+ - LICENSE.txt
106
+ - README.rdoc
107
+ - Rakefile
108
+ - VERSION
109
+ - lib/pl-zip-codes.rb
110
+ - lib/pl-zip-codes/lib.csv
111
+ - lib/pl-zip-codes/pl_zip_codes.rb
112
+ - pl-zip-codes.gemspec
113
+ - test/helper.rb
114
+ - test/test_pl_zip_codes.rb
115
+ homepage: http://github.com/swistaczek/pl-zip-codes
116
+ licenses:
117
+ - MIT
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ! '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ segments:
129
+ - 0
130
+ hash: -4364332944690853949
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ none: false
133
+ requirements:
134
+ - - ! '>='
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 1.8.24
140
+ signing_key:
141
+ specification_version: 3
142
+ summary: Simple zip codes database for Poland
143
+ test_files: []