Class: CnsBrazil::Cns
- Inherits:
-
Object
- Object
- CnsBrazil::Cns
- Defined in:
- lib/cns_brazil/cns.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(value:) ⇒ Cns
constructor
A new instance of Cns.
- #valid? ⇒ Boolean
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
Instance Method Details
#valid? ⇒ 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 |