Sha256: bfc7cf9216af1c524cdfc0527668e4a377641f5ad7b2eb00cc7c761a957a0659

Contents?: true

Size: 827 Bytes

Versions: 4

Compression:

Stored size: 827 Bytes

Contents

module HistoricoAtivos
  class CarregaHistorico

    attr_accessor :parser_header, :parser_trailer, :parser_ativo

    def initialize(parser_header, parser_trailer, parser_ativo)
      @parser_header = parser_header
      @parser_trailer = parser_trailer
      @parser_ativo = parser_ativo
    end

    def load(filepath)
      return false unless File.exists?(filepath)
      
      file = File.open(filepath, "r")

      historico = Historico.new

      file.each { |line|
        historico.import_header @parser_header.parse(line) if line.start_with?("00")
        historico.ativos << @parser_ativo.parse(line) if line.start_with?("01")
        historico.import_trailer @parser_trailer.parse(line) if line.start_with?("99")
      }

      historico
    end

    def persist(historico)
      historico.save
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
bovespa_ingestion-0.3.2 lib/historico_ativos/carrega_historico.rb
bovespa_ingestion-0.3.1 lib/historico_ativos/carrega_historico.rb
bovespa_ingestion-0.3.0 lib/historico_ativos/carrega_historico.rb
bovespa_ingestion-0.2.0 lib/historico_ativos/carrega_historico.rb