Class: PisPasepValidator::PisPasep

Inherits:
Object
  • Object
show all
Defined in:
lib/pis_pasep_validator/pis_pasep.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(number) ⇒ PisPasep

Returns a new instance of PisPasep.



8
9
10
# File 'lib/pis_pasep_validator/pis_pasep.rb', line 8

def initialize(number)
  @number = number.to_s
end

Instance Attribute Details

#numberObject (readonly)

Returns the value of attribute number.



6
7
8
# File 'lib/pis_pasep_validator/pis_pasep.rb', line 6

def number
  @number
end

Class Method Details

.valid?(number) ⇒ Boolean

Returns:

  • (Boolean)


2
3
4
# File 'lib/pis_pasep_validator/pis_pasep.rb', line 2

def self.valid?(number)
  new(number).valid?
end

Instance Method Details

#digit_verificatorObject



20
21
22
# File 'lib/pis_pasep_validator/pis_pasep.rb', line 20

def digit_verificator
  digits[-1]
end

#digitsObject



12
13
14
# File 'lib/pis_pasep_validator/pis_pasep.rb', line 12

def digits
  @digits ||= number.scan(/\d/).map(&:to_i)
end

#plainObject



16
17
18
# File 'lib/pis_pasep_validator/pis_pasep.rb', line 16

def plain
  @plain ||= digits.join
end

#valid?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/pis_pasep_validator/pis_pasep.rb', line 24

def valid?
  formatted? && !black_listed? && digits_matches?
end