Class: CnsBrazil::Cns

Inherits:
Object
  • Object
show all
Defined in:
lib/cns_brazil/cns.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value:) ⇒ Cns

Returns a new instance of Cns.



5
6
7
# File 'lib/cns_brazil/cns.rb', line 5

def initialize(value:)
  @value = value.to_s.gsub(/[^\d]/, '')
end

Class Method Details

.generateObject



18
19
20
21
22
# File 'lib/cns_brazil/cns.rb', line 18

def self.generate
  generator = CnsBrazil::Generator.new

  generator.call
end

Instance Method Details

#valid?Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
15
16
# File 'lib/cns_brazil/cns.rb', line 9

def valid?
  return false if @value.length != 15

  return start_with_1_or_2? if %w[1 2].include?(@value[0])
  return start_with_7_8_or_9? if %w[7 8 9].include?(@value[0])

  false
end