Class: Ubi::Memoria::Document
Overview
Show me your papers!
en.wikipedia.org/wiki/National_identification_number
br: CNPJ us: SSN cl: RUN/RUT
Instance Attribute Summary collapse
-
#number ⇒ Object
readonly
Returns the value of attribute number.
Attributes inherited from Base
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from Base
#==, extract_text, inherited, #initialize, key, name, parse, parse!, plural, #to_s
Constructor Details
This class inherits a constructor from Ubi::Memoria::Base
Instance Attribute Details
#number ⇒ Object (readonly)
Returns the value of attribute number.
12 13 14 |
# File 'lib/ubi/memorias/document.rb', line 12 def number @number end |
Class Method Details
.formats ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/ubi/memorias/document.rb', line 34 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 |
.regex(location = :br) ⇒ Object
42 43 44 |
# File 'lib/ubi/memorias/document.rb', line 42 def regex(location = :br) regexes[location] end |
.regexes ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/ubi/memorias/document.rb', line 26 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 |
Instance Method Details
#format(location = :br) ⇒ Object
18 19 20 |
# File 'lib/ubi/memorias/document.rb', line 18 def format(location = :br) number.sub(*self.class.formats[location]) end |
#parser ⇒ Object
14 15 16 |
# File 'lib/ubi/memorias/document.rb', line 14 def parser @number = text.gsub(/\D/, '') end |