Class: Boletoman::Services::Santander::Boleto::TicketFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/boletoman/services/santander/boleto/ticket_formatter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw) ⇒ TicketFormatter

Returns a new instance of TicketFormatter.



10
11
12
# File 'lib/boletoman/services/santander/boleto/ticket_formatter.rb', line 10

def initialize(raw)
  @raw = raw
end

Instance Attribute Details

#rawObject (readonly)

Returns the value of attribute raw.



8
9
10
# File 'lib/boletoman/services/santander/boleto/ticket_formatter.rb', line 8

def raw
  @raw
end

Instance Method Details

#documentObject



18
19
20
# File 'lib/boletoman/services/santander/boleto/ticket_formatter.rb', line 18

def document
  raw[:payer][:document].remove(/\D/)
end

#document_typeObject



14
15
16
# File 'lib/boletoman/services/santander/boleto/ticket_formatter.rb', line 14

def document_type
  raw[:payer][:document].strip.length == 11 ? "01" : "02"
end

#due_dateObject



46
47
48
# File 'lib/boletoman/services/santander/boleto/ticket_formatter.rb', line 46

def due_date
  raw[:boleto][:due_date].strftime("%d%m%Y")
end

#full_nosso_numeroObject



70
71
72
73
74
75
76
77
# File 'lib/boletoman/services/santander/boleto/ticket_formatter.rb', line 70

def full_nosso_numero
  nosso_numero = raw[:boleto][:nosso_numero]
  verificator_digit = nosso_numero.modulo11(
    multiplicador: (2..9).to_a, mapeamento: { 10 => 0, 11 => 0 }
  ) { |total| 11 - (total % 11) }

  "#{nosso_numero}#{verificator_digit}"
end

#interest_percentageObject



66
67
68
# File 'lib/boletoman/services/santander/boleto/ticket_formatter.rb', line 66

def interest_percentage
  raw[:boleto][:interest_percentage] ? as_int(raw[:boleto][:interest_percentage]) : '00'
end

#issue_dateObject



50
51
52
# File 'lib/boletoman/services/santander/boleto/ticket_formatter.rb', line 50

def issue_date
  (raw[:boleto][:issue_date] || Date.today).strftime("%d%m%Y")
end

#messageObject



79
80
81
# File 'lib/boletoman/services/santander/boleto/ticket_formatter.rb', line 79

def message
  raw[:message]
end

#payer_cityObject



34
35
36
# File 'lib/boletoman/services/santander/boleto/ticket_formatter.rb', line 34

def payer_city
  raw[:payer][:city].first(20)
end

#payer_nameObject



22
23
24
# File 'lib/boletoman/services/santander/boleto/ticket_formatter.rb', line 22

def payer_name
  raw[:payer][:name].first(40)
end

#payer_neighborhoodObject



30
31
32
# File 'lib/boletoman/services/santander/boleto/ticket_formatter.rb', line 30

def payer_neighborhood
  raw[:payer][:neighborhood].first(30)
end

#payer_stateObject



38
39
40
# File 'lib/boletoman/services/santander/boleto/ticket_formatter.rb', line 38

def payer_state
  raw[:payer][:state]
end

#payer_streetObject



26
27
28
# File 'lib/boletoman/services/santander/boleto/ticket_formatter.rb', line 26

def payer_street
  raw[:payer][:street].first(40)
end

#payer_zip_codeObject



42
43
44
# File 'lib/boletoman/services/santander/boleto/ticket_formatter.rb', line 42

def payer_zip_code
  raw[:payer][:zip_code].remove(/\D/)
end

#penalty_daysObject



62
63
64
# File 'lib/boletoman/services/santander/boleto/ticket_formatter.rb', line 62

def penalty_days
  raw[:boleto][:penalty_days] || '00'
end

#penalty_percentageObject



58
59
60
# File 'lib/boletoman/services/santander/boleto/ticket_formatter.rb', line 58

def penalty_percentage
  raw[:boleto][:penalty_percentage] ? as_int(raw[:boleto][:penalty_percentage]) : '00'
end

#valueObject



54
55
56
# File 'lib/boletoman/services/santander/boleto/ticket_formatter.rb', line 54

def value
  as_int(raw[:boleto][:value])
end