module Formagio::Utils

Constants

VERSION

Public Class Methods

add_mask_cnpj(value) click to toggle source
# File lib/formagio/utils.rb, line 45
def self.add_mask_cnpj(value)
  value
end
add_mask_cpf(value) click to toggle source
# File lib/formagio/utils.rb, line 15
def self.add_mask_cpf(value)
  "#{value[0..2]}.#{value[3..5]}.#{value[6..8]}-#{value[9..10]}"
end
is_cnpj?(doc) click to toggle source
# File lib/formagio/utils.rb, line 41
def self.is_cnpj?(doc)
  doc
end
is_cpf?(cpf=nil) click to toggle source
# File lib/formagio/utils.rb, line 19
def self.is_cpf?(cpf=nil)
  return false if cpf.nil?

  black_list = %w{12345678909 11111111111 22222222222 33333333333 44444444444 55555555555 66666666666 77777777777 88888888888 99999999999 00000000000}
  wvalor = cpf.scan /[0-9]/
  if wvalor.length == 11
    unless black_list.member?(wvalor.join)
      wvalor = wvalor.collect{|x| x.to_i}
      wsoma = 10*wvalor[0]+9*wvalor[1]+8*wvalor[2]+7*wvalor[3]+6*wvalor[4]+5*wvalor[5]+4*wvalor[6]+3*wvalor[7]+2*wvalor[8]
      wsoma = wsoma - (11 * (wsoma/11))
      wresult1 = (wsoma == 0 or wsoma == 1) ? 0 : 11 - wsoma
      if wresult1 == wvalor[9]
        wsoma = wvalor[0]*11+wvalor[1]*10+wvalor[2]*9+wvalor[3]*8+wvalor[4]*7+wvalor[5]*6+wvalor[6]*5+wvalor[7]*4+wvalor[8]*3+wvalor[9]*2
        wsoma = wsoma - (11 * (wsoma/11))
        wresult2 = (wsoma == 0 or wsoma == 1) ? 0 : 11 - wsoma
        return true if wresult2 == wvalor[10] # CPF validado
      end
    end
  end
  return false # CPF invalidado
end
is_integer?(value) click to toggle source
# File lib/formagio/utils.rb, line 6
def self.is_integer?(value)
  val2=value.to_i.to_s
  return (val2==value) ? true : false
end
so_numero(value) click to toggle source
# File lib/formagio/utils.rb, line 11
def self.so_numero(value)
  value.scan(/[0-9]/).join
end