Sha256: 9459ef67a45c4132564ac5445a15b98196a89aa4428e59e5992f5035f7c7080c

Contents?: true

Size: 1.93 KB

Versions: 4

Compression:

Stored size: 1.93 KB

Contents

#HUB3 verzija specifikacije
class FinaIzvadak
  DEFINICIJA= {
    "900" => 'a7a50a11a4a8a917a3',
    "903" => 'a7a11a21a3a70a35a8a11a3a3a8a4a4a809a3',
    "905" => 'a2a34a70a35a35a8a8a3a15a1a15a1a15a26a26a4a140a42a35a482a3',
    "907" => 'a21a3a70a3a3a8a8a1a15a1a15a8a15a15a1a15a1a15a1a15a1a15a4a6a420a317a3',
    "909" => 'a8a5a6a978a3',
    "999" => 'a997a3'
  }

  def type(line)
    raise "Duljina mora biti 1000 (dobio duljinu #{line.length} - znakovno: '#{line}')" unless line.length == 1000

    line.unpack('a997a3')[-1]
  end

  def decode(line)
    raise "Ne postoji slog tipa #{type(line)} koji je poslan" if DEFINICIJA[type(line)].nil?

    line.unpack(DEFINICIJA.fetch(type(line))).map(&:strip)
  end

  def prometi(izvadak)
    [].tap do |result|
      grupa = nil
      counter = nil
      izvadak.lines.map do |line|
        decoded = decode(line.chomp)
        tip = decoded[-1]
        if tip == "900"
          next
        elsif tip == "903"
          grupa = decoded
          counter = 0
        elsif tip == "905"
          counter += 1
          result << [
                      grupa[8].to_i,
                      counter,
                      DateTime.parse(grupa[10]),
                      decoded[0] == "10" ? :na_teret : :u_korist,
                      grupa[2],
                      grupa[3],
                      decoded[1],
                      decoded[2],
                      decoded[3],
                      decoded[4],
                      DateTime.parse(decoded[5]),
                      DateTime.parse(decoded[6]),
                      (BigDecimal.new(decoded[11] + decoded[12])/100.0).round(2),
                      decoded[13],
                      decoded[14],
                      decoded[16],
                      decoded[18]
                    ]
        elsif tip == "907"
          next
        elsif tip == "909"
          next
        elsif tip == "999"
          next
        end
      end
    end
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
fina_files-0.0.4 lib/fina_files/fina_izvadak.rb
fina_files-0.0.3 lib/fina_files/fina_izvadak.rb
fina_files-0.0.2 lib/fina_files/fina_izvadak.rb
fina_files-0.0.1 lib/fina_files/fina_izvadak.rb