Class: Boleto
- Inherits:
-
Object
- Object
- Boleto
- Includes:
- BoletoIntermedium
- Defined in:
- lib/BoletoIntermedium/boleto.rb
Constant Summary
Constants included from BoletoIntermedium
Instance Attribute Summary collapse
-
#configuration ⇒ Object
Returns the value of attribute configuration.
-
#due_date ⇒ Object
Returns the value of attribute due_date.
-
#field1 ⇒ Object
Returns the value of attribute field1.
-
#field2 ⇒ Object
Returns the value of attribute field2.
-
#field3 ⇒ Object
Returns the value of attribute field3.
-
#field4 ⇒ Object
Returns the value of attribute field4.
-
#field5 ⇒ Object
Returns the value of attribute field5.
-
#field_dv ⇒ Object
Returns the value of attribute field_dv.
-
#payment_slip ⇒ Object
Returns the value of attribute payment_slip.
-
#value_in_cents ⇒ Object
Returns the value of attribute value_in_cents.
Instance Method Summary collapse
- #bar_code ⇒ Object
- #bar_code_without_verifier ⇒ Object
- #digitable_line ⇒ Object
- #formatted_digitable_line ⇒ Object
-
#initialize(fields = {}) ⇒ Boleto
constructor
A new instance of Boleto.
- #set_field_4 ⇒ Object
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.account @field5 = @due_date + @value_in_cents end |
Instance Attribute Details
#configuration ⇒ Object
Returns the value of attribute configuration.
4 5 6 |
# File 'lib/BoletoIntermedium/boleto.rb', line 4 def configuration @configuration end |
#due_date ⇒ Object
Returns the value of attribute due_date.
8 9 10 |
# File 'lib/BoletoIntermedium/boleto.rb', line 8 def due_date @due_date end |
#field1 ⇒ Object
Returns the value of attribute field1.
10 11 12 |
# File 'lib/BoletoIntermedium/boleto.rb', line 10 def field1 @field1 end |
#field2 ⇒ Object
Returns the value of attribute field2.
12 13 14 |
# File 'lib/BoletoIntermedium/boleto.rb', line 12 def field2 @field2 end |
#field3 ⇒ Object
Returns the value of attribute field3.
14 15 16 |
# File 'lib/BoletoIntermedium/boleto.rb', line 14 def field3 @field3 end |
#field4 ⇒ Object
Returns the value of attribute field4.
16 17 18 |
# File 'lib/BoletoIntermedium/boleto.rb', line 16 def field4 @field4 end |
#field5 ⇒ Object
Returns the value of attribute field5.
17 18 19 |
# File 'lib/BoletoIntermedium/boleto.rb', line 17 def field5 @field5 end |
#field_dv ⇒ Object
Returns the value of attribute field_dv.
11 12 13 |
# File 'lib/BoletoIntermedium/boleto.rb', line 11 def field_dv @field_dv end |
#payment_slip ⇒ Object
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_cents ⇒ Object
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_code ⇒ Object
70 71 72 |
# File 'lib/BoletoIntermedium/boleto.rb', line 70 def [0..3] + BoletoIntermedium.module_11().to_s + [-39..-1] end |
#bar_code_without_verifier ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/BoletoIntermedium/boleto.rb', line 55 def 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.account end |
#digitable_line ⇒ Object
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_line ⇒ Object
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_4 ⇒ Object
51 52 53 |
# File 'lib/BoletoIntermedium/boleto.rb', line 51 def set_field_4 @field4 = BoletoIntermedium.module_11().to_s end |