burocracias 0.0.1

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.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in burocracias.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Neil Carvalho
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Burocracias
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'burocracias'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install burocracias
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'burocracias/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "burocracias"
8
+ gem.version = Burocracias::VERSION
9
+ gem.authors = ["Neil Carvalho"]
10
+ gem.email = ["me@neil.pro"]
11
+ gem.description = %q{Métodos para facilitar o tratamento de CEP, CPF, CNPJ e outras burocracias do nosso Brasil}
12
+ gem.summary = %q{Burocracias do nosso Brasil}
13
+ gem.homepage = ""
14
+
15
+ gem.add_development_dependency 'rspec'
16
+ gem.add_development_dependency 'rake'
17
+
18
+ gem.files = `git ls-files`.split($/)
19
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
20
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
21
+ gem.require_paths = ["lib"]
22
+ end
@@ -0,0 +1,3 @@
1
+ module Burocracias
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,40 @@
1
+ require "burocracias/version"
2
+ require "string"
3
+
4
+ module Burocracias
5
+ class Masks
6
+ def self.format_cpf(string)
7
+ if string.length <= 11
8
+ ("%011d" % string).insert(9, '-').insert(6, '.').insert(3, '.')
9
+ else
10
+ string
11
+ end
12
+ end
13
+
14
+ def self.format_cnpj(string)
15
+ if string.length <= 14
16
+ ("%014d" % string).insert(12, '-').insert(8, '/').insert(5, '.').insert(2, '.')
17
+ else
18
+ string
19
+ end
20
+ end
21
+
22
+ def self.format_cep(string)
23
+ if string.length <= 8
24
+ ("%08d" % string).insert(5, '-').insert(2, '.')
25
+ else
26
+ string
27
+ end
28
+ end
29
+
30
+ def self.format_phone_number(string)
31
+ case string.length
32
+ when 8 then string.insert(4, '-')
33
+ when 9 then string.insert(6, '-').insert(3, '-')
34
+ when 10 then string.insert(6, '-').insert(2, ') ').insert(0, '(')
35
+ when 11 then string.insert(8, '-').insert(5, '-').insert(2, ') ').insert(0, '(')
36
+ else string
37
+ end
38
+ end
39
+ end
40
+ end
data/lib/string.rb ADDED
@@ -0,0 +1,13 @@
1
+ class String
2
+ def as_cpf
3
+ Burocracias::Masks.format_cpf(self)
4
+ end
5
+
6
+ def as_cnpj
7
+ Burocracias::Masks.format_cnpj(self)
8
+ end
9
+
10
+ def as_cep
11
+ Burocracias::Masks.format_cep(self)
12
+ end
13
+ end
@@ -0,0 +1,103 @@
1
+ require 'rubygems'
2
+ require 'rspec'
3
+ require 'burocracias'
4
+
5
+ module Burocracias
6
+ describe Masks do
7
+ describe '::format_cpf(string)' do
8
+ context 'string has length of 11 characters' do
9
+ it 'returns string as 999.999.999-99' do
10
+ cpf = "12345678909"
11
+ Masks.format_cpf(cpf).should eq '123.456.789-09'
12
+ end
13
+ end
14
+ context 'string has length of less than 11 characters' do
15
+ it 'adds zeroes do fill 11 characters and masks it' do
16
+ cpf = '123'
17
+ Masks.format_cpf(cpf).should eq '000.000.001-23'
18
+ end
19
+ end
20
+ context 'string has length of more than 11 characters' do
21
+ it 'returns self' do
22
+ cpf = '1234567891234'
23
+ Masks.format_cpf(cpf).should eq cpf
24
+ end
25
+ end
26
+ end
27
+
28
+ describe '::format_cnpj(string)' do
29
+ context 'string has length of 14 characters' do
30
+ it 'returns string as 99.999.999/9999-99' do
31
+ cnpj = '99999999999999'
32
+ Masks.format_cnpj(cnpj).should eq '99.999.999/9999-99'
33
+ end
34
+ end
35
+ context 'string has length of less than 14 characters' do
36
+ it 'adds zeroes to fill 14 characters and masks it' do
37
+ cnpj = '123456789'
38
+ Masks.format_cnpj(cnpj).should eq '00.000.123/4567-89'
39
+ end
40
+ end
41
+ context 'string has length of more than 14 characters' do
42
+ it 'returns self' do
43
+ cnpj = '1234567890123456789'
44
+ Masks.format_cnpj(cnpj).should eq cnpj
45
+ end
46
+ end
47
+ end
48
+
49
+ describe '::format_cep(string)' do
50
+ context 'string has length of 8 characters' do
51
+ it 'returns string as 99.999-999' do
52
+ cep = '20921005'
53
+ Masks.format_cep(cep).should eq '20.921-005'
54
+ end
55
+ end
56
+ context 'string has less than 8 characters' do
57
+ it 'adds zeroes to fill 8 characters and masks it' do
58
+ cep = '20921'
59
+ Masks.format_cep(cep).should eq '00.020-921'
60
+ end
61
+ end
62
+ context 'string has more than 8 characters' do
63
+ it 'returns self' do
64
+ cep = '1234567890'
65
+ Masks.format_cep(cep).should eq cep
66
+ end
67
+ end
68
+ end
69
+
70
+ describe '::format_phone_number(string)' do
71
+ context 'string has 8 digits' do
72
+ it 'returns string as 9999-9999' do
73
+ phone = '55556666'
74
+ Masks.format_phone_number(phone).should eq '5555-6666'
75
+ end
76
+ end
77
+ context 'string has 10 digits' do
78
+ it 'returns string as (99) 9999-9999' do
79
+ phone = '4455556666'
80
+ Masks.format_phone_number(phone).should eq '(44) 5555-6666'
81
+ end
82
+ end
83
+ context 'string has 9 digits' do
84
+ it 'returns string as 999-999-999' do
85
+ phone = '111222333'
86
+ Masks.format_phone_number(phone).should eq '111-222-333'
87
+ end
88
+ end
89
+ context 'string has 11 digits' do
90
+ it 'returns string as (99) 999-999-999' do
91
+ phone = '44555666777'
92
+ Masks.format_phone_number(phone).should eq '(44) 555-666-777'
93
+ end
94
+ end
95
+ context 'any other case' do
96
+ it 'returns self' do
97
+ phone = '123'
98
+ Masks.format_phone_number(phone).should eq phone
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,2 @@
1
+ require 'rubygems'
2
+ require 'rspec'
@@ -0,0 +1,19 @@
1
+ describe String do
2
+ describe '#as_cpf' do
3
+ it 'formats string as CPF' do
4
+ '12345678909'.as_cpf.should eq '123.456.789-09'
5
+ end
6
+ end
7
+
8
+ describe '#as_cnpj' do
9
+ it 'formats string as CNPJ' do
10
+ '99999999999999'.as_cnpj.should eq '99.999.999/9999-99'
11
+ end
12
+ end
13
+
14
+ describe '#as_cep' do
15
+ it 'formats string as CEP' do
16
+ '12345678'.as_cep.should eq '12.345-678'
17
+ end
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: burocracias
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Neil Carvalho
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
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: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
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: '0'
46
+ description: Métodos para facilitar o tratamento de CEP, CPF, CNPJ e outras burocracias
47
+ do nosso Brasil
48
+ email:
49
+ - me@neil.pro
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE.txt
57
+ - README.md
58
+ - Rakefile
59
+ - burocracias.gemspec
60
+ - lib/burocracias.rb
61
+ - lib/burocracias/version.rb
62
+ - lib/string.rb
63
+ - spec/burocracias_spec.rb
64
+ - spec/spec_helper.rb
65
+ - spec/string_spec.rb
66
+ homepage: ''
67
+ licenses: []
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ segments:
79
+ - 0
80
+ hash: 1646754669709975798
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ segments:
88
+ - 0
89
+ hash: 1646754669709975798
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 1.8.24
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: Burocracias do nosso Brasil
96
+ test_files:
97
+ - spec/burocracias_spec.rb
98
+ - spec/spec_helper.rb
99
+ - spec/string_spec.rb