Class: Complicode::Invoice

Inherits:
Object
  • Object
show all
Defined in:
lib/complicode/invoice.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Invoice

Returns a new instance of Invoice.

Options Hash (attributes):

  • :nit (String)
  • :number (String)
  • :amount (String)
  • :issue_date (String)

12
13
14
15
16
17
# File 'lib/complicode/invoice.rb', line 12

def initialize(attributes = {})
  @nit = attributes.fetch(:nit, "0").to_s
  @number = attributes.fetch(:number).to_s
  @amount = attributes.fetch(:amount).to_s.tr(",", ".").to_f.round.to_s
  @issue_date = Date.parse(attributes.fetch(:issue_date).to_s).strftime("%Y%m%d")
end

Instance Attribute Details

#amountObject

Returns the value of attribute amount


5
6
7
# File 'lib/complicode/invoice.rb', line 5

def amount
  @amount
end

#issue_dateObject

Returns the value of attribute issue_date


5
6
7
# File 'lib/complicode/invoice.rb', line 5

def issue_date
  @issue_date
end

#nitObject

Returns the value of attribute nit


5
6
7
# File 'lib/complicode/invoice.rb', line 5

def nit
  @nit
end

#numberObject

Returns the value of attribute number


5
6
7
# File 'lib/complicode/invoice.rb', line 5

def number
  @number
end

Instance Method Details

#append_checksum_digit_to(attribute) ⇒ Object


20
21
22
# File 'lib/complicode/invoice.rb', line 20

def append_checksum_digit_to(attribute)
  append_to(attribute, Verhoeff.checksum_digit_of(send(attribute)).to_s)
end

#append_to(attribute, value) ⇒ Object


26
27
28
# File 'lib/complicode/invoice.rb', line 26

def append_to(attribute, value)
  send("#{attribute}=", send(attribute) + value)
end

#concatString


36
37
38
# File 'lib/complicode/invoice.rb', line 36

def concat
  [number, nit, issue_date, amount].inject(:+)
end

#sumInteger


31
32
33
# File 'lib/complicode/invoice.rb', line 31

def sum
  [number, nit, issue_date, amount].map(&:to_i).inject(:+)
end