Class: HistoricoAtivos::CarregaHistorico
- Inherits:
-
Object
- Object
- HistoricoAtivos::CarregaHistorico
- Defined in:
- lib/historico_ativos/carrega_historico.rb
Instance Attribute Summary collapse
-
#parser_ativo ⇒ Object
Returns the value of attribute parser_ativo.
-
#parser_header ⇒ Object
Returns the value of attribute parser_header.
-
#parser_trailer ⇒ Object
Returns the value of attribute parser_trailer.
Instance Method Summary collapse
-
#initialize(parser_header, parser_trailer, parser_ativo) ⇒ CarregaHistorico
constructor
A new instance of CarregaHistorico.
- #load(filepath) ⇒ Object
- #persist(historico) ⇒ Object
Constructor Details
#initialize(parser_header, parser_trailer, parser_ativo) ⇒ CarregaHistorico
Returns a new instance of CarregaHistorico.
6 7 8 9 10 |
# File 'lib/historico_ativos/carrega_historico.rb', line 6 def initialize(parser_header, parser_trailer, parser_ativo) @parser_header = parser_header @parser_trailer = parser_trailer @parser_ativo = parser_ativo end |
Instance Attribute Details
#parser_ativo ⇒ Object
Returns the value of attribute parser_ativo.
4 5 6 |
# File 'lib/historico_ativos/carrega_historico.rb', line 4 def parser_ativo @parser_ativo end |
#parser_header ⇒ Object
Returns the value of attribute parser_header.
4 5 6 |
# File 'lib/historico_ativos/carrega_historico.rb', line 4 def parser_header @parser_header end |
#parser_trailer ⇒ Object
Returns the value of attribute parser_trailer.
4 5 6 |
# File 'lib/historico_ativos/carrega_historico.rb', line 4 def parser_trailer @parser_trailer end |
Instance Method Details
#load(filepath) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/historico_ativos/carrega_historico.rb', line 12 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 |
#persist(historico) ⇒ Object
28 29 30 |
# File 'lib/historico_ativos/carrega_historico.rb', line 28 def persist(historico) historico.save end |