Module: CpfCnpj
Overview
Synapses Group
Instance Attribute Summary collapse
-
#number ⇒ Object
readonly
Returns the value of attribute number.
Instance Method Summary collapse
Instance Attribute Details
#number ⇒ Object (readonly)
Returns the value of attribute number.
6 7 8 |
# File 'lib/cpf_cnpj/cpf_cnpj.rb', line 6 def number @number end |
Instance Method Details
#==(value) ⇒ Object
20 21 22 |
# File 'lib/cpf_cnpj/cpf_cnpj.rb', line 20 def ==(value) self.number == value.number end |
#initialize(number) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/cpf_cnpj/cpf_cnpj.rb', line 8 def initialize(number) @number = number @match = self.instance_of?(Cpf) ? @number =~ CPF_REGEX : @number =~ CNPJ_REGEX @plain_number = $1 @verification_number = $2 @number = (@match ? format_number! : nil) end |
#to_s ⇒ Object
16 17 18 |
# File 'lib/cpf_cnpj/cpf_cnpj.rb', line 16 def to_s @number || "" end |
#valid? ⇒ Boolean
24 25 26 27 |
# File 'lib/cpf_cnpj/cpf_cnpj.rb', line 24 def valid? return false unless @match verify_number end |