Class: Brid::TituloEleitor

Inherits:
GenericID show all
Defined in:
lib/brid/ids/titulo_eleitor.rb

Instance Attribute Summary

Attributes inherited from GenericID

#number

Instance Method Summary collapse

Methods inherited from GenericID

#check_digits, #check_digits_length, #freeze, #invalid_sequential?, #valid?

Constructor Details

#initialize(number) ⇒ TituloEleitor

Returns a new instance of TituloEleitor.



5
6
7
# File 'lib/brid/ids/titulo_eleitor.rb', line 5

def initialize number
  @number = clear_number(number).rjust number_length, '0'
end

Instance Method Details

#number_lengthObject



3
# File 'lib/brid/ids/titulo_eleitor.rb', line 3

def number_length; 12; end

#originObject



26
27
28
29
30
31
32
33
34
# File 'lib/brid/ids/titulo_eleitor.rb', line 26

def origin
  @origin ||= begin
    [ nil, :sp, :mg, :rj, :rs, :ba, :pr, :ce,
      :pe, :sc, :go, :ma, :pb, :pa, :es,
      :pi, :rn, :al, :mt, :ms, :df, :se,
      :am, :ro, :ac, :ap, :rr, :to, :exterior
    ][uf_digit.to_i]
  end
end

#sequentialObject



10
11
12
13
14
# File 'lib/brid/ids/titulo_eleitor.rb', line 10

def sequential 
  @sequential ||= begin
    @number[/^(.*)....$/, 1]
  end
end

#to_sObject



22
23
24
# File 'lib/brid/ids/titulo_eleitor.rb', line 22

def to_s
  @number.scan(/\d{4}/).join ' '
end

#uf_digitObject



16
17
18
19
20
# File 'lib/brid/ids/titulo_eleitor.rb', line 16

def uf_digit
  @uf_digit ||= begin
    @number[/(..)..$/, 1]
  end
end