br_inscricao_estadual 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +1 -0
  3. data/.gitignore +18 -0
  4. data/.travis.yml +3 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE +674 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +40 -0
  9. data/Rakefile +16 -0
  10. data/br_inscricao_estadual.gemspec +29 -0
  11. data/lib/br_inscricao_estadual/ac.rb +12 -0
  12. data/lib/br_inscricao_estadual/al.rb +15 -0
  13. data/lib/br_inscricao_estadual/am.rb +21 -0
  14. data/lib/br_inscricao_estadual/ap.rb +37 -0
  15. data/lib/br_inscricao_estadual/ba.rb +16 -0
  16. data/lib/br_inscricao_estadual/ba_8.rb +14 -0
  17. data/lib/br_inscricao_estadual/ba_9.rb +15 -0
  18. data/lib/br_inscricao_estadual/base.rb +27 -0
  19. data/lib/br_inscricao_estadual/ce.rb +7 -0
  20. data/lib/br_inscricao_estadual/common.rb +54 -0
  21. data/lib/br_inscricao_estadual/df.rb +7 -0
  22. data/lib/br_inscricao_estadual/es.rb +12 -0
  23. data/lib/br_inscricao_estadual/go.rb +38 -0
  24. data/lib/br_inscricao_estadual/ma.rb +8 -0
  25. data/lib/br_inscricao_estadual/mg.rb +10 -0
  26. data/lib/br_inscricao_estadual/ms.rb +8 -0
  27. data/lib/br_inscricao_estadual/mt.rb +9 -0
  28. data/lib/br_inscricao_estadual/pa.rb +8 -0
  29. data/lib/br_inscricao_estadual/pb.rb +7 -0
  30. data/lib/br_inscricao_estadual/pe.rb +8 -0
  31. data/lib/br_inscricao_estadual/pi.rb +7 -0
  32. data/lib/br_inscricao_estadual/pr.rb +10 -0
  33. data/lib/br_inscricao_estadual/rj.rb +9 -0
  34. data/lib/br_inscricao_estadual/rn.rb +8 -0
  35. data/lib/br_inscricao_estadual/rn_10.rb +18 -0
  36. data/lib/br_inscricao_estadual/rn_9.rb +17 -0
  37. data/lib/br_inscricao_estadual/ro.rb +24 -0
  38. data/lib/br_inscricao_estadual/rr.rb +14 -0
  39. data/lib/br_inscricao_estadual/rs.rb +14 -0
  40. data/lib/br_inscricao_estadual/sc.rb +4 -0
  41. data/lib/br_inscricao_estadual/se.rb +6 -0
  42. data/lib/br_inscricao_estadual/sp.rb +27 -0
  43. data/lib/br_inscricao_estadual/sp_p.rb +15 -0
  44. data/lib/br_inscricao_estadual/to.rb +16 -0
  45. data/lib/br_inscricao_estadual/version.rb +3 -0
  46. data/lib/br_inscricao_estadual.rb +41 -0
  47. data/spec/br_inscricao_estadual/ac_spec.rb +16 -0
  48. data/spec/br_inscricao_estadual/al_spec.rb +16 -0
  49. data/spec/br_inscricao_estadual/am_spec.rb +26 -0
  50. data/spec/br_inscricao_estadual/ap_spec.rb +40 -0
  51. data/spec/br_inscricao_estadual/ba_spec.rb +48 -0
  52. data/spec/br_inscricao_estadual/base_spec.rb +19 -0
  53. data/spec/br_inscricao_estadual/ce_spec.rb +16 -0
  54. data/spec/br_inscricao_estadual/df_spec.rb +21 -0
  55. data/spec/br_inscricao_estadual/es_spec.rb +16 -0
  56. data/spec/br_inscricao_estadual/go_spec.rb +36 -0
  57. data/spec/br_inscricao_estadual/ma_spec.rb +16 -0
  58. data/spec/br_inscricao_estadual/mg_spec.rb +16 -0
  59. data/spec/br_inscricao_estadual/ms_spec.rb +16 -0
  60. data/spec/br_inscricao_estadual/mt_spec.rb +16 -0
  61. data/spec/br_inscricao_estadual/pa_spec.rb +16 -0
  62. data/spec/br_inscricao_estadual/pb_spec.rb +16 -0
  63. data/spec/br_inscricao_estadual/pe_spec.rb +16 -0
  64. data/spec/br_inscricao_estadual/pi_spec.rb +16 -0
  65. data/spec/br_inscricao_estadual/pr_spec.rb +16 -0
  66. data/spec/br_inscricao_estadual/rj_spec.rb +16 -0
  67. data/spec/br_inscricao_estadual/rn_spec.rb +27 -0
  68. data/spec/br_inscricao_estadual/ro_spec.rb +26 -0
  69. data/spec/br_inscricao_estadual/rr_spec.rb +18 -0
  70. data/spec/br_inscricao_estadual/rs_spec.rb +16 -0
  71. data/spec/br_inscricao_estadual/sc_spec.rb +16 -0
  72. data/spec/br_inscricao_estadual/se_spec.rb +16 -0
  73. data/spec/br_inscricao_estadual/sp_spec.rb +25 -0
  74. data/spec/br_inscricao_estadual/to_spec.rb +21 -0
  75. data/spec/br_inscricao_estadual_spec.rb +8 -0
  76. data/spec/spec_helper.rb +12 -0
  77. metadata +264 -0
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Yuri Poloni
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,40 @@
1
+ # BrInscricaoEstadual
2
+ [![Code Climate](https://codeclimate.com/repos/521e0704f3ea00689f04ef93/badges/1457e87b327bdd3dac02/gpa.png)](https://codeclimate.com/repos/521e0704f3ea00689f04ef93/feed)
3
+ [![Build Status](https://travis-ci.org/Pull4up/br_inscricao_estadual.png)](http://travis-ci.org/Pull4up/br_inscricao_estadual)
4
+ [![Coverage Status](https://coveralls.io/repos/Pull4up/br_inscricao_estadual/badge.png)](https://coveralls.io/r/Pull4up/br_inscricao_estadual)
5
+
6
+ Validação de inscrição estadual para ruby
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'br_inscricao_estadual'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install br_inscricao_estadual
21
+
22
+ ## Usage
23
+ insc_est = BrInscricaoEstadual::Base.new(inscricao_estadual,uf) # uf values 'AC','RS'....
24
+ insc_est.valid? # if valid return true else false
25
+
26
+ Exemplo:
27
+ insc_est = BrInscricaoEstadual::Base.new('01.004.823/001-12','AC')
28
+ insc_est.valid?
29
+
30
+ ## Contributing
31
+
32
+ 1. Fork it
33
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
34
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
35
+ 4. Push to the branch (`git push origin my-new-feature`)
36
+ 5. Create new Pull Request
37
+ =======
38
+ br_inscricao_estadual
39
+ =====================
40
+
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rdoc/task'
4
+ Rake::RDocTask.new do |rdoc|
5
+ rdoc.title = 'br_inscricao_estadual'
6
+ rdoc.main = "README.rdoc"
7
+ rdoc.rdoc_dir = 'doc'
8
+ rdoc.rdoc_files.include("README.rdoc","lib/**/*.rb")
9
+ # rdoc.generator = 'darkfish'
10
+ end
11
+
12
+ require 'rspec/core/rake_task'
13
+ RSpec::Core::RakeTask.new(:spec)
14
+
15
+ task :test => :spec
16
+ task :default => :spec
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'br_inscricao_estadual/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "br_inscricao_estadual"
8
+ spec.version = BrInscricaoEstadual::VERSION
9
+ spec.authors = ["Yuri Poloni"]
10
+ spec.email = ["yuripoloni@gmail.com","yuri.poloni@pull4up.com.br"]
11
+ spec.description = %q{A Ruby validate state registration on Brazil. Validação de Inscrição Estadual}
12
+ spec.summary = %q{A Ruby validate state registration on Brazil with http://www.sintegra.gov.br/insc_est.html}
13
+ spec.homepage = "https://github.com/Pull4up/br_inscricao_estadual"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency 'rdoc', '~> 4.0'
24
+ spec.add_development_dependency "rspec", "~> 2.13"
25
+ spec.add_development_dependency "pry", "~> 0.9"
26
+ spec.add_development_dependency "pry-nav", "~> 0.2"
27
+ spec.add_development_dependency "simplecov", "~> 0.7"
28
+ spec.add_development_dependency "coveralls", "~> 0.6"
29
+ end
@@ -0,0 +1,12 @@
1
+ module BrInscricaoEstadual
2
+ class AC < Common
3
+ protected
4
+ PESO = [4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]
5
+ PESO2 = [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]
6
+ STATE_CODE = "01"
7
+ STATE_INSC_SIZE = 13
8
+ DIGITS_ZERO = [10,11]
9
+
10
+
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+ module BrInscricaoEstadual
2
+ class AL < Common
3
+ def valid?
4
+ super && type
5
+ end
6
+
7
+ protected
8
+ STATE_CODE = "24"
9
+ DIGITS_ZERO = [10]
10
+
11
+ def type
12
+ %w(0 3 5 7 8).include?(self.insc_est[2])
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,21 @@
1
+ module BrInscricaoEstadual
2
+ class AM < Common
3
+ protected
4
+ PESO = [9, 9, 9, 9, 9, 9, 9, 9]
5
+ DIGITS_ZERO = [10]
6
+
7
+ def calculate_verify(peso)
8
+ result = calculate(peso)
9
+ digit_verify_inscription(result)
10
+ end
11
+
12
+
13
+ def digit_verify_inscription(result)
14
+ if (result > 11)
15
+ result = (result%11)
16
+ return 0 if result <= 1
17
+ end
18
+ (11 - result)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,37 @@
1
+ module BrInscricaoEstadual
2
+ class AP < Common
3
+ protected
4
+ STATE_CODE = "03"
5
+ DIGITS_ZERO = [10]
6
+
7
+ def calculate(peso)
8
+ calc = super
9
+ calc + values_p_d[:p]
10
+ end
11
+
12
+ def digit_verify_inscription(result)
13
+ if self.class::DIGITS_ZERO.include?(result)
14
+ 0
15
+ elsif result == 11
16
+ values_p_d[:d]
17
+ else
18
+ result
19
+ end
20
+ end
21
+
22
+ def values_p_d
23
+ @p_d ||= track_registry
24
+ end
25
+
26
+ def track_registry
27
+ insc_est_arr = self.insc_est.split('').collect(&:to_i).take(PESO.size).join().to_i
28
+ if insc_est_arr >= 3000001 && insc_est_arr <= 3017000 then
29
+ {p: 5, d: 0}
30
+ elsif insc_est_arr >= 3017001 && insc_est_arr <= 3019022 then
31
+ {p: 9, d: 1}
32
+ elsif insc_est_arr >= 3019023 then
33
+ {p: 0, d: 0}
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,16 @@
1
+ module BrInscricaoEstadual
2
+ class BA < Common
3
+ def valid?
4
+ return (self.insc_est.size == 8) ? BA8.new(insc_est).valid? : BA9.new(insc_est).valid?
5
+ end
6
+ end
7
+
8
+ module BACommon
9
+ def calculate_verify(peso)
10
+ num_mod = (self.insc_est.start_with?('6','7','9') ? 11 : 10)
11
+ result = (num_mod - calculate(peso)%num_mod)
12
+ digit_verify_inscription(result)
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+ module BrInscricaoEstadual
2
+ class BA8 < Common
3
+ include BACommon
4
+
5
+ protected
6
+ PESO2 = [7, 6, 5, 4, 3, 2]
7
+ PESO = [8, 7, 6, 5, 4, 3, 0, 2]
8
+ STATE_INSC_SIZE = 8
9
+ DIGITS_ZERO = [0,10,11]
10
+ DIGITO_LEVEL1=6
11
+ DIGITO_LEVEL2=7
12
+
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ module BrInscricaoEstadual
2
+ class BA9 < Common
3
+ include BACommon
4
+
5
+ protected
6
+ PESO = [9, 8, 7, 6, 5, 4, 3, 0, 2]
7
+ PESO2 = [8, 7, 6, 5, 4, 3, 2]
8
+ DIGITS_ZERO = [0,10,11]
9
+ DIGITO_LEVEL1=7
10
+ DIGITO_LEVEL2=8
11
+
12
+
13
+
14
+ end
15
+ end
@@ -0,0 +1,27 @@
1
+ module BrInscricaoEstadual
2
+ class Base
3
+ def initialize(inscricao,uf)
4
+ self.kclass = BrInscricaoEstadual.const_get(safe_object(uf)).new(inscricao)
5
+ end
6
+
7
+ def valid?
8
+ kclass.valid?
9
+ end
10
+
11
+ protected
12
+ def kclass
13
+ @kclass
14
+ end
15
+
16
+ def kclass=(kclass)
17
+ @kclass = kclass
18
+ end
19
+
20
+ private
21
+ def safe_object(camel_cased_word)
22
+ raise unless camel_cased_word =~ /\A[A-Za-z]{2}\z/
23
+ camel_cased_word.upcase
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,7 @@
1
+ module BrInscricaoEstadual
2
+ class CE < Common
3
+ protected
4
+ DIGITS_ZERO = [10,11]
5
+
6
+ end
7
+ end
@@ -0,0 +1,54 @@
1
+ module BrInscricaoEstadual
2
+ class Common
3
+ DIGITS_ZERO = [0,1,10,11]
4
+ STATE_INSC_SIZE = 9
5
+ PESO = [9, 8, 7, 6, 5, 4, 3, 2]
6
+
7
+ attr_accessor :insc_est
8
+
9
+ def initialize(insc_est)
10
+ self.insc_est = insc_est.gsub(/\D*/,'')
11
+ end
12
+
13
+ def valid?
14
+ self.class.const_defined?('STATE_CODE') ? (size_verify && state_code && digit_verify) : (size_verify && digit_verify)
15
+ end
16
+
17
+ def calculate_verify(peso)
18
+ result = (11 - calculate(peso)%11)
19
+ digit_verify_inscription(result)
20
+ end
21
+
22
+ def calculate(peso)
23
+ @calc = []
24
+ self.insc_est.split('').collect(&:to_i).take(peso.size).each_with_index{|item, index| @calc << (item * peso[index]) }
25
+ @calc.inject(:+)
26
+ end
27
+
28
+ def digit_verify_inscription(result)
29
+ self.class::DIGITS_ZERO.include?(result) ? 0 : result
30
+ end
31
+
32
+ def state_code
33
+ return self.insc_est[0..1] == self.class::STATE_CODE if self.class::STATE_CODE.is_a?(String)
34
+ return self.class::STATE_CODE.include?(self.insc_est[0..1]) if self.class::STATE_CODE.is_a?(Array)
35
+ end
36
+
37
+ def digit_verify
38
+ digito1 = calculate_verify(self.class::PESO)
39
+ return false unless self.insc_est[(self.class::DIGITO_LEVEL1||=self.class::PESO.size)].to_i == digito1 #[0,1].include?(digito1) &&
40
+
41
+ if self.class.const_defined?('PESO2')
42
+ digito2 = calculate_verify(self.class::PESO2)
43
+ return false unless self.insc_est[(self.class::DIGITO_LEVEL2||=self.class::PESO2.size)].to_i == digito2 #[0,2].include?(digito2) &&
44
+ end
45
+
46
+ true
47
+ end
48
+
49
+ def size_verify
50
+ self.insc_est.size == self.class::STATE_INSC_SIZE
51
+ end
52
+
53
+ end
54
+ end
@@ -0,0 +1,7 @@
1
+ module BrInscricaoEstadual
2
+ class DF < AC
3
+ protected
4
+ STATE_CODE = "07"
5
+
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ module BrInscricaoEstadual
2
+ class ES < Common
3
+ protected
4
+ DIGITS_ZERO = [0,1]
5
+
6
+ def calculate_verify(peso)
7
+ result = (calculate(peso)%11)
8
+ digit_verify_inscription(result)
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,38 @@
1
+ module BrInscricaoEstadual
2
+ class GO < Common
3
+ protected
4
+ STATE_CODE = ["10", "11", "15"]
5
+ DIGITS_ZERO = [0]
6
+
7
+ def digit_verify_inscription(result)
8
+ if insc_int_arr.take(PESO.size).join().to_i == 11094402 then
9
+ return insc_int_arr.last if [1,0].include?(insc_int_arr.last)
10
+ end
11
+
12
+ verify_result(result)
13
+ end
14
+
15
+ def calculate_verify(peso)
16
+ result = calculate(peso)%11
17
+ digit_verify_inscription(result)
18
+ end
19
+
20
+ def insc_int_arr
21
+ self.insc_est.split('').collect(&:to_i)
22
+ end
23
+
24
+ def insc_int_arr_take
25
+ insc_int_arr.take(PESO.size).join().to_i
26
+ end
27
+
28
+ def verify_result(result)
29
+ if self.class::DIGITS_ZERO.include?(result)
30
+ 0
31
+ elsif result == 1
32
+ (insc_int_arr_take >= 10103105 && insc_int_arr_take <= 10119997) ? 1 : 0
33
+ else
34
+ (11 - result%11)
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,8 @@
1
+ module BrInscricaoEstadual
2
+ class MA < Common
3
+ protected
4
+ STATE_CODE = "12"
5
+ DIGITS_ZERO = [0,1]
6
+
7
+ end
8
+ end
@@ -0,0 +1,10 @@
1
+ module BrInscricaoEstadual
2
+ class MG < Common
3
+ protected
4
+ PESO = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1]
5
+ PESO2 = [3, 2, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2]
6
+ STATE_INSC_SIZE = 13
7
+ DIGITS_ZERO = [0]
8
+
9
+ end
10
+ end
@@ -0,0 +1,8 @@
1
+ module BrInscricaoEstadual
2
+ class MS < Common
3
+ protected
4
+ STATE_CODE = "28"
5
+ DIGITS_ZERO = [0,10,11]
6
+
7
+ end
8
+ end
@@ -0,0 +1,9 @@
1
+ module BrInscricaoEstadual
2
+ class MT < Common
3
+ protected
4
+ PESO = [3, 2, 9, 8, 7, 6, 5, 4, 3, 2]
5
+ STATE_INSC_SIZE = 11
6
+ DIGITS_ZERO = [0,1]
7
+
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ module BrInscricaoEstadual
2
+ class PA < Common
3
+ protected
4
+ STATE_CODE = "15"
5
+ DIGITS_ZERO = [0,1]
6
+
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ module BrInscricaoEstadual
2
+ class PB < Common
3
+ protected
4
+ DIGITS_ZERO = [10,11]
5
+
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ module BrInscricaoEstadual
2
+ class PE < Common
3
+ protected
4
+ PESO = [8, 7, 6, 5, 4, 3, 2]
5
+ PESO2 = [9, 8, 7, 6, 5, 4, 3, 2]
6
+
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ module BrInscricaoEstadual
2
+ class PI < Common
3
+ protected
4
+ DIGITS_ZERO = [10,11]
5
+
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ module BrInscricaoEstadual
2
+ class PR < Common
3
+ protected
4
+ PESO = [3, 2, 7, 6, 5, 4, 3, 2]
5
+ PESO2 = [4, 3, 2, 7, 6, 5, 4, 3, 2]
6
+ STATE_INSC_SIZE = 10
7
+ DIGITS_ZERO = [0,1,10,11]
8
+
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ module BrInscricaoEstadual
2
+ class RJ < Common
3
+ protected
4
+ PESO = [2, 7, 6, 5, 4, 3, 2]
5
+ STATE_INSC_SIZE = 8
6
+
7
+
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ module BrInscricaoEstadual
2
+ class RN < Common
3
+ def valid?
4
+ return (self.insc_est.size == 9) ? RN9.new(insc_est).valid? : RN10.new(insc_est).valid?
5
+ end
6
+
7
+ end
8
+ end
@@ -0,0 +1,18 @@
1
+ module BrInscricaoEstadual
2
+ class RN10 < Common
3
+ protected
4
+ PESO = [10, 9, 8, 7, 6, 5, 4, 3, 2]
5
+ STATE_CODE = "20"
6
+ STATE_INSC_SIZE = 10
7
+ DIGITS_ZERO = [10]
8
+
9
+ def calculate(peso)
10
+ super * 10
11
+ end
12
+
13
+ def calculate_verify(peso)
14
+ result = calculate(peso)%11
15
+ digit_verify_inscription(result)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,17 @@
1
+ module BrInscricaoEstadual
2
+ class RN9 < Common
3
+ protected
4
+ STATE_CODE = "20"
5
+ DIGITS_ZERO = [10]
6
+
7
+
8
+ def calculate(peso)
9
+ super * 10
10
+ end
11
+
12
+ def calculate_verify(peso)
13
+ result = calculate(peso)%11
14
+ digit_verify_inscription(result)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,24 @@
1
+ module BrInscricaoEstadual
2
+ class RO < Common
3
+ def initialize(insc_est)
4
+ self.insc_est = insc_est.gsub(/\D*/,'')
5
+ convert_to_new_format if self.insc_est.size == 9
6
+ end
7
+
8
+ protected
9
+ PESO = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]
10
+ STATE_INSC_SIZE = 14
11
+ DIGITS_ZERO = [10]
12
+
13
+ def convert_to_new_format
14
+ self.insc_est = "00000000" + self.insc_est[3..-1]
15
+ end
16
+
17
+ def calculate_verify(peso)
18
+ result = (11 - calculate(peso)%11)
19
+ result -= 10 if result > 10
20
+ digit_verify_inscription(result)
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,14 @@
1
+ module BrInscricaoEstadual
2
+ class RR < Common
3
+ protected
4
+ STATE_CODE = "24"
5
+ DIGITS_ZERO = [0]
6
+ PESO = [1, 2, 3, 4, 5, 6, 7, 8]
7
+
8
+ def calculate_verify(peso)
9
+ result = calculate(peso)%9
10
+ digit_verify_inscription(result)
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ module BrInscricaoEstadual
2
+ class RS < Common
3
+ # Este é necessário um churrasco para validar =]!
4
+ # Criada na base do chima!
5
+
6
+ protected
7
+ PESO = [2, 9, 8, 7, 6, 5, 4, 3, 2]
8
+ DIGITS_ZERO = [10,11]
9
+ STATE_INSC_SIZE = 10
10
+
11
+
12
+
13
+ end
14
+ end
@@ -0,0 +1,4 @@
1
+ module BrInscricaoEstadual
2
+ class SC < Common
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ module BrInscricaoEstadual
2
+ class SE < Common
3
+ protected
4
+ DIGITS_ZERO = [10,11]
5
+ end
6
+ end
@@ -0,0 +1,27 @@
1
+ module BrInscricaoEstadual
2
+ class SP < Common
3
+ attr_accessor :contryside
4
+
5
+ def initialize(insc_est)
6
+ self.contryside = insc_est.start_with?("P","p")
7
+ self.insc_est = insc_est.gsub(/\D*/,'')
8
+ end
9
+
10
+ def valid?
11
+ self.contryside ? SPP.new(self.insc_est).valid? : super
12
+ end
13
+
14
+ protected
15
+ PESO = [1, 3, 4, 5, 6, 7, 8, 10]
16
+ PESO2= [3, 2, 10, 9, 8, 7, 6, 5, 4, 3, 2]
17
+ STATE_INSC_SIZE = 12
18
+ DIGITS_ZERO = [0,1,10,11]
19
+
20
+
21
+ def calculate_verify(peso)
22
+ result = calculate(peso)%11
23
+ digit_verify_inscription(result)
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,15 @@
1
+ module BrInscricaoEstadual
2
+ class SPP < Common
3
+ protected
4
+ PESO = [1, 3, 4, 5, 6, 7, 8, 10]
5
+ STATE_INSC_SIZE = 12
6
+ DIGITS_ZERO = [0,10]
7
+
8
+ def calculate_verify(peso)
9
+ result = (calculate(peso)%11)
10
+ result -= 10 if result > 10
11
+ digit_verify_inscription(result)
12
+ end
13
+
14
+ end
15
+ end