ceps 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8e6c5306fd2ad80bdd6663776b0d48fccf445f21
4
- data.tar.gz: 4235a3a60f49cbcca3be83d5bd81475a20558d03
3
+ metadata.gz: 8b3a7b380c76920d10a307a1e23f28bdf5d2a407
4
+ data.tar.gz: 70d587c1ed83c16db19eafb6977d0a636ac8690e
5
5
  SHA512:
6
- metadata.gz: 191cb4ec2fceaabbf1d9d17c379025f93245bfa945eb8a33212c79dbfa2689314b696f1976d96e900e2f008c4e3485befb45fc782fcd2ba0f306122b1e394d69
7
- data.tar.gz: ac54e7a5d459cb408d8be745c6dc93afbca1ba1dc758b34466bf44832e07ac054672123595f45b10ddc59238ff0354109528d6cf8942520d5850994b124ce7e7
6
+ metadata.gz: c8a6379551b631c0c6b74b2f0538ac7ce329f195042fd510a3a82cbfa490f1be4d2243bc00cd0b757f11dff46a0dbbaa98b67030492029745026aad5e50df97f
7
+ data.tar.gz: e8c19492b98dc4c912ff11df30b04493bc00c0c04030d22c945e5b86af6ca661988faf771fbdb94fd85d426244e2052163447d7aca79fc90dfdde79fd1df9de6
data/.gitignore CHANGED
@@ -0,0 +1,21 @@
1
+ *.gem
2
+ *.rbc
3
+ *.swp
4
+ *.swo
5
+ .bundle
6
+ .config
7
+ .yardoc
8
+ Gemfile.lock
9
+ InstalledFiles
10
+ _yardoc
11
+ coverage
12
+ doc/
13
+ lib/bundler/man
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
20
+ .ruby-version
21
+ .ruby-gemset
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.2.0
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+ gem 'rake'
3
+ gem 'mdb'
4
+ gem 'ruby-progressbar'
5
+ # gem 'geocoder'
6
+ # gem 'retryable'
7
+
8
+ # Specify your gem's dependencies in countries.gemspec
9
+ gemspec
data/README.md CHANGED
@@ -0,0 +1,43 @@
1
+ CEPs
2
+ ====
3
+
4
+ Ceps is a collection of all sorts of useful information about every brazilian CEP packaged as pretty little cep objects.
5
+
6
+ [![Build Status](https://travis-ci.org/theprogramer/ceps.png)](https://travis-ci.org/theprogramer/ceps)
7
+
8
+ Installation
9
+ ------------
10
+
11
+ gem install ceps
12
+
13
+ Basic Usage
14
+ -----------
15
+
16
+ Simply load a new CEP object using Cep.new(23045000) or the shortcut Cep[23045000].
17
+
18
+ c = Cep.new(23045400)
19
+ c = Cep.new[23045400]
20
+
21
+ Cep Info
22
+ --------
23
+
24
+ Address
25
+
26
+ c.location #=> "Peter Pan"
27
+ c.type #=> "Rua"
28
+ c.neighborhood #=> "Campo Grande"
29
+ c.city #=> "Rio de Janeiro"
30
+ c.state #=> "Rio de Janeiro"
31
+
32
+ ToDo
33
+ ----
34
+
35
+ * Geocoding
36
+ * Tests
37
+ * Import scripts
38
+
39
+ Note about GPBe (Guia Postal Brasileiro Eletrônico)
40
+ ---------------------------------------------------
41
+
42
+ To generate ceps.yaml data file it is necessary get a valid version of a GPBe.
43
+ GPBe is property of Correios do Brasil SA.
data/Rakefile ADDED
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env rake
2
+ require 'bundler/gem_tasks'
3
+
4
+ require 'rake'
5
+ require 'rspec/core/rake_task'
6
+
7
+ desc 'Run all examples'
8
+ RSpec::Core::RakeTask.new(:spec) do |t|
9
+ t.rspec_opts = %w(--color --warnings)
10
+ end
11
+
12
+ task default: [:spec]
13
+
14
+
15
+ desc 'Import MDB file'
16
+ task :import do
17
+
18
+ require 'mdb'
19
+ require_relative 'lib/ceps/mdb'
20
+ require 'ruby-progressbar'
21
+
22
+ db = Mdb.open ARGV[1]
23
+ puts "Loading routes"
24
+ puts "This should take some time!"
25
+ routes = db["LOG_LOGRADOURO"]
26
+ puts "Loading neighborhoods"
27
+ neighborhoods = db["LOG_BAIRRO"]
28
+ puts "Loading cities"
29
+ cities = db["LOG_LOCALIDADE"]
30
+ puts "Loading states"
31
+ states = db["LOG_FAIXA_UF"]
32
+
33
+ ceps = {}
34
+ puts "Generating new hash"
35
+ progressbar = ProgressBar.create title: "Progress",
36
+ starting_at: 0,
37
+ total: routes.count,
38
+ format: "%c from %C |%b>>%i| %a (%e) %p%%"
39
+ routes.each do |route|
40
+ cep = Correios::Mdb.decript route[:LOG_KEY_DNE]
41
+ ceps[cep.to_sym] = {
42
+ location: route[:LOG_NO],
43
+ type: route[:LOG_TIPO_LOGRADOURO],
44
+ city: cities.select{|c| c[:LOC_NU_SEQUENCIAL] == route[:LOC_NU_SEQUENCIAL].to_s}.first[:LOC_NO],
45
+ state: states.select{|s| s[:UFE_SG] == route[:UFE_SG]}.first[:UFE_NO],
46
+ neighborhood: neighborhoods.select{|n| n[:BAI_NU_SEQUENCIAL] == route[:BAI_NU_SEQUENCIAL_INI].to_s}.first[:BAI_NO]
47
+ }
48
+ progressbar.increment
49
+ progressbar.refresh
50
+ end
51
+ puts "Saving new ceps.yaml"
52
+ File.open('ceps.yml','w') do |h|
53
+ h.write ceps.to_yaml
54
+ end
55
+ end
data/lib/ceps/mdb.rb ADDED
@@ -0,0 +1,38 @@
1
+ module Correios
2
+
3
+ class Mdb
4
+
5
+ def self.decript(cep = "")
6
+ decripted = ""
7
+ unless cep.empty?
8
+ cep.scan(/../).each do |k|
9
+ case k
10
+ when "X8", "CN", "8X", "NC"
11
+ decripted << "1"
12
+ when "Z0", "EP", "0Z", "PE"
13
+ decripted << "2"
14
+ when "1B", "GR", "B1", "RG"
15
+ decripted << "3"
16
+ when "3D", "ID", "D3", "DI"
17
+ decripted << "4"
18
+ when "4C", "JS", "C4", "SJ"
19
+ decripted << "5"
20
+ when "2A", "HQ", "A2", "QH"
21
+ decripted << "6"
22
+ when "09", "FO", "90", "OF"
23
+ decripted << "7"
24
+ when "Y7", "DM", "7Y", "MD"
25
+ decripted << "8"
26
+ when "5V", "BK", "V5", "KB"
27
+ decripted << "9"
28
+ when "UG", "AL", "GU", "LA"
29
+ decripted << "0"
30
+ end
31
+ end
32
+ end
33
+ decripted
34
+ end
35
+
36
+ end
37
+
38
+ end
data/lib/ceps/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ceps
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
data/lib/data/ceps.yaml CHANGED
@@ -2,24 +2,24 @@
2
2
  10000000:
3
3
  location: Paulista
4
4
  type: Rua
5
- neighbourhood: Centro
5
+ neighborhood: Centro
6
6
  city: São Paulo
7
7
  state: São Paulo
8
8
  20000000:
9
9
  location: Carioca
10
10
  type: Rua
11
- neighbourhood: Centro
11
+ neighborhood: Centro
12
12
  city: Rio de Janeiro
13
13
  state: Rio de Janeiro
14
14
  20000500:
15
15
  location: Carioquinha
16
16
  type: Avenida
17
- neighbourhood: Copacabana
17
+ neighborhood: Copacabana
18
18
  city: Rio de Janeiro
19
19
  state: Rio de Janeiro
20
20
  30000000:
21
21
  location: Mineira
22
22
  type: Avenida
23
- neighbourhood: Centro
23
+ neighborhood: Centro
24
24
  city: Belo Horizonte
25
25
  state: Minas Gerais
data/spec/cep_spec.rb ADDED
@@ -0,0 +1,85 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
4
+
5
+ describe Correios::Cep do
6
+
7
+ let(:cep) { Correios::Cep.new(20000000) }
8
+
9
+ it 'allows to create a cep object from an integer' do
10
+ cep = described_class.new(20000000)
11
+ expect(cep.data).not_to be_nil
12
+ end
13
+
14
+ it 'should return Carioca location' do
15
+ expect(cep.location).to eq('Carioca')
16
+ end
17
+
18
+ it 'should return Rua type' do
19
+ expect(cep.type).to eq('Rua')
20
+ end
21
+
22
+ it 'should return Centro neighborhood' do
23
+ expect(cep.neighborhood).to eq('Centro')
24
+ end
25
+
26
+ it 'should return Rio de Janeiro city name' do
27
+ expect(cep.city).to eq('Rio de Janeiro')
28
+ end
29
+
30
+ it 'should return Rio de Janeiro state name' do
31
+ expect(cep.state).to eq('Rio de Janeiro')
32
+ end
33
+
34
+ describe 'valid?' do
35
+ it 'should return true if cep is valid' do
36
+ expect(Correios::Cep.new(10000000)).to be_valid
37
+ end
38
+
39
+ it 'should return false if cep is invalid' do
40
+ expect(Correios::Cep.new({})).not_to be_valid
41
+ end
42
+ end
43
+
44
+ describe 'new' do
45
+ it 'should return new cep object when a valid cep string is passed' do
46
+ expect(Correios::Cep.new(20000000)).to be_a(Correios::Cep)
47
+ end
48
+
49
+ it 'should return nil when an invalid cep is passed' do
50
+ expect(Correios::Cep.new(00000000)).to be_nil
51
+ end
52
+
53
+ end
54
+
55
+ describe 'Cep class' do
56
+ context "when loaded via 'Correios' existance" do
57
+ subject { defined?(Cep) }
58
+
59
+ it { is_expected.to be_falsey }
60
+ end
61
+
62
+ context "when loaded via 'ceps'" do
63
+ before { require 'ceps' }
64
+
65
+ describe 'existance' do
66
+ subject { defined?(Cep) }
67
+
68
+ it { is_expected.to be_truthy }
69
+ end
70
+
71
+ describe 'superclass' do
72
+ subject { Cep.superclass }
73
+
74
+ it { is_expected.to eq(Correios::Cep) }
75
+ end
76
+
77
+ # describe 'to_s' do
78
+ # it 'should return the cep key' do
79
+ # expect(Cep.new(20000000).to_s).to eq('20000-000')
80
+ # end
81
+ # end
82
+ end
83
+ end
84
+
85
+ end
@@ -0,0 +1,10 @@
1
+ # enconding: utf-8
2
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
+
4
+ describe Correios::Setup do
5
+ let(:setup) { Correios::Setup.new }
6
+
7
+ it 'responds to ceps' do
8
+ expect(setup.ceps).to be_a Hash
9
+ end
10
+ end
@@ -0,0 +1 @@
1
+ require 'correios'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ceps
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thiago Miranda
@@ -33,14 +33,22 @@ extensions: []
33
33
  extra_rdoc_files: []
34
34
  files:
35
35
  - ".gitignore"
36
+ - ".rspec"
37
+ - ".travis.yml"
38
+ - Gemfile
36
39
  - README.md
40
+ - Rakefile
37
41
  - ceps.gemspec
38
42
  - lib/ceps.rb
39
43
  - lib/ceps/cep.rb
44
+ - lib/ceps/mdb.rb
40
45
  - lib/ceps/setup.rb
41
46
  - lib/ceps/version.rb
42
47
  - lib/correios.rb
43
48
  - lib/data/ceps.yaml
49
+ - spec/cep_spec.rb
50
+ - spec/setup_spec.rb
51
+ - spec/spec_helper.rb
44
52
  homepage: http://github.com/theprogramer/ceps
45
53
  licenses: []
46
54
  metadata: {}
@@ -64,4 +72,7 @@ rubygems_version: 2.2.2
64
72
  signing_key:
65
73
  specification_version: 4
66
74
  summary: Gives you a cep object full of all sorts of useful information.
67
- test_files: []
75
+ test_files:
76
+ - spec/cep_spec.rb
77
+ - spec/setup_spec.rb
78
+ - spec/spec_helper.rb