Class: Boleto

Inherits:
Object
  • Object
show all
Includes:
BoletoIntermedium
Defined in:
lib/BoletoIntermedium/boleto.rb

Constant Summary

Constants included from BoletoIntermedium

BoletoIntermedium::VERSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BoletoIntermedium

bank_epoque, configure, module_10, module_11

Constructor Details

#initialize(fields = {}) ⇒ Boleto

Returns a new instance of Boleto.



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/BoletoIntermedium/boleto.rb', line 19

def initialize(fields = {})
  @payment_slip     = fields[:payment_slip] ? fields[:payment_slip].to_s[0..6].rjust(7, '0') : '0000000'
  @value_in_cents   = (fields[:value_in_cents] || 0).to_s[0..9].rjust(10, '0')
  @due_date         = (fields[:due_date] ? BoletoIntermedium.bank_epoque(fields[:due_date]) : BoletoIntermedium.bank_epoque(Date.today + 1.week)).to_s[0..3].rjust(4, '0')

  config = BoletoIntermedium.configuration

  self.field1 = config.bank_code + config.currency_code + config.agency + config.product + config.wallet[0]
  self.field2 = config.wallet[1] + config.system + @payment_slip
  self.field3 = config.

  @field5 = @due_date + @value_in_cents
end

Instance Attribute Details

#configurationObject

Returns the value of attribute configuration.



4
5
6
# File 'lib/BoletoIntermedium/boleto.rb', line 4

def configuration
  @configuration
end

#due_dateObject

Returns the value of attribute due_date.



8
9
10
# File 'lib/BoletoIntermedium/boleto.rb', line 8

def due_date
  @due_date
end

#field1Object

Returns the value of attribute field1.



10
11
12
# File 'lib/BoletoIntermedium/boleto.rb', line 10

def field1
  @field1
end

#field2Object

Returns the value of attribute field2.



12
13
14
# File 'lib/BoletoIntermedium/boleto.rb', line 12

def field2
  @field2
end

#field3Object

Returns the value of attribute field3.



14
15
16
# File 'lib/BoletoIntermedium/boleto.rb', line 14

def field3
  @field3
end

#field4Object

Returns the value of attribute field4.



16
17
18
# File 'lib/BoletoIntermedium/boleto.rb', line 16

def field4
  @field4
end

#field5Object

Returns the value of attribute field5.



17
18
19
# File 'lib/BoletoIntermedium/boleto.rb', line 17

def field5
  @field5
end

#field_dvObject

Returns the value of attribute field_dv.



11
12
13
# File 'lib/BoletoIntermedium/boleto.rb', line 11

def field_dv
  @field_dv
end

#payment_slipObject

Returns the value of attribute payment_slip.



6
7
8
# File 'lib/BoletoIntermedium/boleto.rb', line 6

def payment_slip
  @payment_slip
end

#value_in_centsObject

Returns the value of attribute value_in_cents.



7
8
9
# File 'lib/BoletoIntermedium/boleto.rb', line 7

def value_in_cents
  @value_in_cents
end

Instance Method Details

#bar_codeObject



70
71
72
# File 'lib/BoletoIntermedium/boleto.rb', line 70

def bar_code
  bar_code_without_verifier[0..3] + BoletoIntermedium.module_11(bar_code_without_verifier).to_s + bar_code_without_verifier[-39..-1]
end

#bar_code_without_verifierObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/BoletoIntermedium/boleto.rb', line 55

def bar_code_without_verifier
  config = BoletoIntermedium.configuration

  config.bank_code +
      config.currency_code +
      due_date +
      value_in_cents +
      config.agency +
      config.product +
      config.wallet +
      config.system +
      payment_slip +
      config.
end

#digitable_lineObject



74
75
76
77
78
79
80
81
82
83
# File 'lib/BoletoIntermedium/boleto.rb', line 74

def digitable_line
  (@field1 || '') +
      (@field1_dv || '') +
      (@field2 || '') +
      (@field2_dv || '') +
      (@field3 || '') +
      (@field3_dv || '') +
      (@field4 || '') +
      (@field5 || '')
end

#formatted_digitable_lineObject



85
86
87
88
89
90
91
92
93
94
# File 'lib/BoletoIntermedium/boleto.rb', line 85

def formatted_digitable_line
  digitable_line[0..4] +
      '.' + digitable_line[5..9] +
      ' ' + digitable_line[10..14] +
      '.' + digitable_line[15..20] +
      ' ' + digitable_line[21..25] +
      '.' + digitable_line[26..31] +
      ' ' + digitable_line[32] +
      ' ' + digitable_line[33..46]
end

#set_field_4Object



51
52
53
# File 'lib/BoletoIntermedium/boleto.rb', line 51

def set_field_4
  @field4 = BoletoIntermedium.module_11(bar_code_without_verifier).to_s
end