Class: Boletoman::Services::Santander::Boleto::TicketFormatter
- Inherits:
-
Object
- Object
- Boletoman::Services::Santander::Boleto::TicketFormatter
- Defined in:
- lib/boletoman/services/santander/boleto/ticket_formatter.rb
Instance Attribute Summary collapse
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
Instance Method Summary collapse
- #document ⇒ Object
- #document_type ⇒ Object
- #due_date ⇒ Object
- #full_nosso_numero ⇒ Object
-
#initialize(raw) ⇒ TicketFormatter
constructor
A new instance of TicketFormatter.
- #interest_percentage ⇒ Object
- #issue_date ⇒ Object
- #message ⇒ Object
- #payer_city ⇒ Object
- #payer_name ⇒ Object
- #payer_neighborhood ⇒ Object
- #payer_state ⇒ Object
- #payer_street ⇒ Object
- #payer_zip_code ⇒ Object
- #penalty_days ⇒ Object
- #penalty_percentage ⇒ Object
- #value ⇒ Object
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
#raw ⇒ Object (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
#document ⇒ Object
18 19 20 |
# File 'lib/boletoman/services/santander/boleto/ticket_formatter.rb', line 18 def document raw[:payer][:document].remove(/\D/) end |
#document_type ⇒ Object
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_date ⇒ Object
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_numero ⇒ Object
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_percentage ⇒ Object
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_date ⇒ Object
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 |
#message ⇒ Object
79 80 81 |
# File 'lib/boletoman/services/santander/boleto/ticket_formatter.rb', line 79 def raw[:message] end |
#payer_city ⇒ Object
34 35 36 |
# File 'lib/boletoman/services/santander/boleto/ticket_formatter.rb', line 34 def payer_city raw[:payer][:city].first(20) end |
#payer_name ⇒ Object
22 23 24 |
# File 'lib/boletoman/services/santander/boleto/ticket_formatter.rb', line 22 def payer_name raw[:payer][:name].first(40) end |
#payer_neighborhood ⇒ Object
30 31 32 |
# File 'lib/boletoman/services/santander/boleto/ticket_formatter.rb', line 30 def payer_neighborhood raw[:payer][:neighborhood].first(30) end |
#payer_state ⇒ Object
38 39 40 |
# File 'lib/boletoman/services/santander/boleto/ticket_formatter.rb', line 38 def payer_state raw[:payer][:state] end |
#payer_street ⇒ Object
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_code ⇒ Object
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_days ⇒ Object
62 63 64 |
# File 'lib/boletoman/services/santander/boleto/ticket_formatter.rb', line 62 def penalty_days raw[:boleto][:penalty_days] || '00' end |
#penalty_percentage ⇒ Object
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 |
#value ⇒ Object
54 55 56 |
# File 'lib/boletoman/services/santander/boleto/ticket_formatter.rb', line 54 def value as_int(raw[:boleto][:value]) end |