Class: BR::CPF
- Inherits:
-
Object
- Object
- BR::CPF
- Extended by:
- CPFWrapper
- Defined in:
- lib/br/cpf.rb,
lib/br/cpf/version.rb
Constant Summary collapse
- CPF_MIN =
1
- CPF_MAX =
999999999
- VERSION =
"1.0.1"
Instance Attribute Summary collapse
-
#cpf ⇒ Object
readonly
Returns the value of attribute cpf.
-
#verif ⇒ Object
readonly
Returns the value of attribute verif.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(raiz) ⇒ CPF
constructor
A new instance of CPF.
- #raiz ⇒ Object
- #raiz=(raiz) ⇒ Object
- #to_i ⇒ Object
- #to_s ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(raiz) ⇒ CPF
Returns a new instance of CPF.
13 14 15 |
# File 'lib/br/cpf.rb', line 13 def initialize(raiz) self.raiz = raiz end |
Instance Attribute Details
#cpf ⇒ Object (readonly)
Returns the value of attribute cpf.
11 12 13 |
# File 'lib/br/cpf.rb', line 11 def cpf @cpf end |
#verif ⇒ Object (readonly)
Returns the value of attribute verif.
11 12 13 |
# File 'lib/br/cpf.rb', line 11 def verif @verif end |
Class Method Details
.valid?(cpf) ⇒ Boolean
33 34 35 36 37 38 39 |
# File 'lib/br/cpf.rb', line 33 def self.valid?(cpf) if cpf.is_a? String is_valid(cpf.to_i) else is_valid(cpf) end end |
Instance Method Details
#raiz ⇒ Object
29 30 31 |
# File 'lib/br/cpf.rb', line 29 def raiz @raiz end |
#raiz=(raiz) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/br/cpf.rb', line 21 def raiz=(raiz) @raiz = raiz.to_i raise ArgumentError, "raiz should be between #{CPF_MIN} and #{CPF_MAX}" if @raiz < CPF_MIN or @raiz > CPF_MAX @cpf = self.class.calc_check_digit(@raiz) @verif = @cpf % 100 @valid = true end |
#to_i ⇒ Object
41 42 43 |
# File 'lib/br/cpf.rb', line 41 def to_i @cpf end |
#to_s ⇒ Object
45 46 47 |
# File 'lib/br/cpf.rb', line 45 def to_s "%011d" % @cpf end |
#valid? ⇒ Boolean
17 18 19 |
# File 'lib/br/cpf.rb', line 17 def valid? @valid end |