Sha256: d4cc02d63b07ba04ccbe2c54d50dcd065c30cefe9b47fc05e5b3224dcbb03809
Contents?: true
Size: 1023 Bytes
Versions: 3
Compression:
Stored size: 1023 Bytes
Contents
module Ubi module Memoria # Show me your papers! # # https://en.wikipedia.org/wiki/National_identification_number # # br: CNPJ # us: SSN # cl: RUN/RUT # class Document < Base attr_reader :number def parser @number = text.gsub(/\D/, '') end def format(location = :br) number.sub(*self.class.formats[location]) end # # Class methods # class << self def regexes { br: /(\d{14}|\d{2}\.?\d{3}\.?\d{3}\/?\d{4}\-?\d{2})/, cl: /\d{2}\.\d{3}\.\d{3}[-][0-9kK]/, us: /\d{3}[-]\d{2}[-]\d{4}/ } end def formats { br: [/(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})/, '\1.\2.\3/\4-\5'], cl: [/(\d{2})(\d{3})(\d{3})(\d{1})/, '\1.\2.\3-\4'], us: [/(\d{3})(\d{2})(\d{4})/, '\1-\2-\3'] } end def regex(location = :br) regexes[location] end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
ubi-0.0.8 | lib/ubi/memorias/document.rb |
ubi-0.0.7 | lib/ubi/memorias/document.rb |
ubi-0.0.5 | lib/ubi/memorias/document.rb |