Class: Brid::TituloEleitor

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

Instance Method Summary collapse

Methods inherited from GenericID

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

Constructor Details

#initialize(number) ⇒ TituloEleitor

Returns a new instance of TituloEleitor.



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

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

  raise ArgumentError.new "invalid number" if @number.length != number_length
end

Instance Method Details

#number_lengthObject



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

def number_length; 12; end

#originObject



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

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



12
13
14
15
16
# File 'lib/brid/ids/titulo_eleitor.rb', line 12

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

#to_sObject



24
25
26
# File 'lib/brid/ids/titulo_eleitor.rb', line 24

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

#uf_digitObject



18
19
20
21
22
# File 'lib/brid/ids/titulo_eleitor.rb', line 18

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