Class: ZbrojniNalogGenerator
- Inherits:
-
Object
- Object
- ZbrojniNalogGenerator
- Defined in:
- lib/fina_files/zbrojni_nalog_generator.rb
Instance Attribute Summary collapse
-
#datum ⇒ Object
Returns the value of attribute datum.
-
#iban_platitelj ⇒ Object
readonly
Returns the value of attribute iban_platitelj.
-
#nalozi ⇒ Object
Returns the value of attribute nalozi.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
Instance Method Summary collapse
- #export(file_name) ⇒ Object
-
#initialize(iban_platitelj) ⇒ ZbrojniNalogGenerator
constructor
A new instance of ZbrojniNalogGenerator.
- #row_300 ⇒ Object
- #row_301 ⇒ Object
- #row_309(nalog) ⇒ Object
- #row_399 ⇒ Object
- #zbroj_to_s ⇒ Object
Constructor Details
#initialize(iban_platitelj) ⇒ ZbrojniNalogGenerator
7 8 9 10 11 12 |
# File 'lib/fina_files/zbrojni_nalog_generator.rb', line 7 def initialize(iban_platitelj) @rows = [] @nalozi = [] @datum = DateTime.now @iban_platitelj = iban_platitelj end |
Instance Attribute Details
#datum ⇒ Object
Returns the value of attribute datum.
4 5 6 |
# File 'lib/fina_files/zbrojni_nalog_generator.rb', line 4 def datum @datum end |
#iban_platitelj ⇒ Object (readonly)
Returns the value of attribute iban_platitelj.
5 6 7 |
# File 'lib/fina_files/zbrojni_nalog_generator.rb', line 5 def iban_platitelj @iban_platitelj end |
#nalozi ⇒ Object
Returns the value of attribute nalozi.
4 5 6 |
# File 'lib/fina_files/zbrojni_nalog_generator.rb', line 4 def nalozi @nalozi end |
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
5 6 7 |
# File 'lib/fina_files/zbrojni_nalog_generator.rb', line 5 def rows @rows end |
Instance Method Details
#export(file_name) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/fina_files/zbrojni_nalog_generator.rb', line 45 def export(file_name) File.open(File.(file_name), 'w:Windows-1250') do |file| rows.each do |row| encoded = (row + "\r\n").force_encoding("Windows-1250") file.write(encoded) end end end |
#row_300 ⇒ Object
21 22 23 |
# File 'lib/fina_files/zbrojni_nalog_generator.rb', line 21 def row_300 datum.strftime('%Y%m%d') + "1701" + " "*985 + "300" end |
#row_301 ⇒ Object
25 26 27 |
# File 'lib/fina_files/zbrojni_nalog_generator.rb', line 25 def row_301 "#{@iban_platitelj}HRK" + " "*24 + "%05d" % nalozi.count + zbroj_to_s + datum.strftime('%Y%m%d') + " "*916 + "301" end |
#row_309(nalog) ⇒ Object
29 30 31 |
# File 'lib/fina_files/zbrojni_nalog_generator.rb', line 29 def row_309(nalog) nalog[3].ljust(34) + nalog[4].ljust(70) + " "*73 + nalog[0].gsub(" ","").ljust(26) + " "*4 + nalog[2].ljust(140) +("%016.2f" % nalog[5]).gsub(".","") + nalog[1].gsub(" ","").ljust(26) + " "*159 + "0" + " "*449 + "309" end |
#row_399 ⇒ Object
41 42 43 |
# File 'lib/fina_files/zbrojni_nalog_generator.rb', line 41 def row_399 " "*997 + "399" end |
#zbroj_to_s ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/fina_files/zbrojni_nalog_generator.rb', line 33 def zbroj_to_s raise 'nema naloga' if nalozi.count == 0 amount = nalozi.map do |nalog| BigDecimal.new(nalog[5].to_s).round(2) end.reduce(:+) ("%021.2f" % amount).gsub(".","") end |