Class: ValidatorIE::StateAP

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
lib/validator_ie/core/state_ap.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ StateAP

Returns a new instance of StateAP.



12
13
14
15
16
17
# File 'lib/validator_ie/core/state_ap.rb', line 12

def initialize(opts={})
  opts.each do |key, value|
    self.public_send("#{key}=", value)
  end
  @p = @d = 0
end

Instance Attribute Details

#numberObject

Returns the value of attribute number.



6
7
8
# File 'lib/validator_ie/core/state_ap.rb', line 6

def number
  @number
end

Instance Method Details

#number_should_code_stateObject



19
20
21
# File 'lib/validator_ie/core/state_ap.rb', line 19

def number_should_code_state
  number[0..1].eql?('03')
end

#number_should_mod11Object



33
34
35
36
37
# File 'lib/validator_ie/core/state_ap.rb', line 33

def number_should_mod11
  result = number_should_modX(11, 7)
  return if result
  errors.add(:number, 'não é válido para inscrição estadual.')
end

#number_should_range_codeObject



23
24
25
26
27
28
29
30
31
# File 'lib/validator_ie/core/state_ap.rb', line 23

def number_should_range_code
  if number.to_i.between?(3000001, 3017000)
      @p = 5
      @d = 0
  elsif number.to_i.between?(3017001, 3019022)
      @p = 9
      @d = 1
  end
end