bovespa_ingestion 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +11 -0
- data/Gemfile.lock +49 -0
- data/README.md +51 -0
- data/Rakefile +37 -0
- data/VERSION +1 -0
- data/archives/SeriesHistoricas_Layout.pdf +0 -0
- data/bin/carregar_historico +22 -0
- data/bovespa_ingestion.gemspec +80 -0
- data/config/environment.rb +10 -0
- data/db/config.yml +22 -0
- data/db/migrate/20111221001450_create_historico.rb +15 -0
- data/db/migrate/20111222192119_create_ativos.rb +28 -0
- data/db/migrate/20111223004105_change_ativos.rb +10 -0
- data/db/migrate/20111223023840_add_quantidade_ativos_to_historico_ativos.rb +9 -0
- data/db/migrate/20111223131703_add_prazo_termo_to_ativo.rb +9 -0
- data/db/migrate/20111223213342_alter_reference_historico_ativo.rb +13 -0
- data/db/migrate/20111223214919_remove_data_importacao.rb +9 -0
- data/db/schema.rb +51 -0
- data/lib/historico_ativos/ativo.rb +6 -0
- data/lib/historico_ativos/carrega_historico.rb +32 -0
- data/lib/historico_ativos/header.rb +5 -0
- data/lib/historico_ativos/historico.rb +17 -0
- data/lib/historico_ativos/parser_ativo.rb +114 -0
- data/lib/historico_ativos/parser_header.rb +32 -0
- data/lib/historico_ativos/parser_trailer.rb +17 -0
- data/lib/historico_ativos/trailer.rb +5 -0
- data/lib/historico_ativos.rb +9 -0
- data/sample/DemoCotacoesHistoricas12022003.txt +553 -0
- data/sample/sample_cota_hist_2003.txt +4 -0
- data/spec/historico_ativos/ativo_spec.rb +12 -0
- data/spec/historico_ativos/carrega_historico_spec.rb +77 -0
- data/spec/historico_ativos/historico_spec.rb +40 -0
- data/spec/historico_ativos/parser_ativo_spec.rb +91 -0
- data/spec/historico_ativos/parser_header_spec.rb +31 -0
- data/spec/historico_ativos/parser_trailer_spec.rb +24 -0
- data/spec/spec_helper.rb +1 -0
- metadata +124 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activemodel (3.1.3)
|
5
|
+
activesupport (= 3.1.3)
|
6
|
+
builder (~> 3.0.0)
|
7
|
+
i18n (~> 0.6)
|
8
|
+
activerecord (3.1.3)
|
9
|
+
activemodel (= 3.1.3)
|
10
|
+
activesupport (= 3.1.3)
|
11
|
+
arel (~> 2.2.1)
|
12
|
+
tzinfo (~> 0.3.29)
|
13
|
+
activesupport (3.1.3)
|
14
|
+
multi_json (~> 1.0)
|
15
|
+
arel (2.2.1)
|
16
|
+
builder (3.0.0)
|
17
|
+
diff-lcs (1.1.3)
|
18
|
+
git (1.2.5)
|
19
|
+
i18n (0.6.0)
|
20
|
+
jeweler (1.6.4)
|
21
|
+
bundler (~> 1.0)
|
22
|
+
git (>= 1.2.5)
|
23
|
+
rake
|
24
|
+
multi_json (1.0.4)
|
25
|
+
rake (0.9.2.2)
|
26
|
+
rspec (2.7.0)
|
27
|
+
rspec-core (~> 2.7.0)
|
28
|
+
rspec-expectations (~> 2.7.0)
|
29
|
+
rspec-mocks (~> 2.7.0)
|
30
|
+
rspec-core (2.7.1)
|
31
|
+
rspec-expectations (2.7.0)
|
32
|
+
diff-lcs (~> 1.1.2)
|
33
|
+
rspec-mocks (2.7.0)
|
34
|
+
sqlite3 (1.3.5)
|
35
|
+
standalone_migrations (1.0.5)
|
36
|
+
activerecord (>= 3)
|
37
|
+
rake
|
38
|
+
tzinfo (0.3.31)
|
39
|
+
|
40
|
+
PLATFORMS
|
41
|
+
ruby
|
42
|
+
|
43
|
+
DEPENDENCIES
|
44
|
+
activerecord (>= 3)
|
45
|
+
jeweler (~> 1.6.4)
|
46
|
+
rake
|
47
|
+
rspec (~> 2)
|
48
|
+
sqlite3
|
49
|
+
standalone_migrations
|
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
Bovespa Ingestion
|
2
|
+
=============
|
3
|
+
|
4
|
+
An importer/parser of BM&F Bovespa historical stock quotations files.
|
5
|
+
|
6
|
+
Introduction
|
7
|
+
------------
|
8
|
+
|
9
|
+
Installing
|
10
|
+
----------
|
11
|
+
|
12
|
+
Install bundler:
|
13
|
+
|
14
|
+
$ gem install bundler
|
15
|
+
|
16
|
+
Enter the cloned dir and fetch dependencies:
|
17
|
+
|
18
|
+
$ bundler install
|
19
|
+
|
20
|
+
Contributing
|
21
|
+
------------
|
22
|
+
|
23
|
+
1) Fork this git repository
|
24
|
+
|
25
|
+
2) Push your changes to your own repository
|
26
|
+
|
27
|
+
3) Send a pull request
|
28
|
+
|
29
|
+
Running
|
30
|
+
-------
|
31
|
+
|
32
|
+
Run the test application:
|
33
|
+
|
34
|
+
$ bin/carregar_historico
|
35
|
+
|
36
|
+
Testing
|
37
|
+
-------
|
38
|
+
|
39
|
+
We use rspec, so:
|
40
|
+
|
41
|
+
$ rspec spec
|
42
|
+
|
43
|
+
or simply:
|
44
|
+
|
45
|
+
$ rake
|
46
|
+
|
47
|
+
Prerequisites
|
48
|
+
-------------
|
49
|
+
|
50
|
+
Tested with Ruby 1.9.2
|
51
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'tasks/standalone_migrations'
|
6
|
+
rescue LoadError => e
|
7
|
+
puts "gem install standalone_migrations to get db:migrate:* tasks! (Error: #{e})"
|
8
|
+
end
|
9
|
+
|
10
|
+
RSpec::Core::RakeTask.new 'rspec' do |t|
|
11
|
+
t.pattern = 'spec/historico_ativos/*_spec.rb'
|
12
|
+
t.rspec_opts = ['--tty', '--color', '--format documentation']
|
13
|
+
end
|
14
|
+
|
15
|
+
task :default => [:rspec]
|
16
|
+
|
17
|
+
# rake install -> install gem locally (for tests)
|
18
|
+
# rake release -> push to github and release to gemcutter
|
19
|
+
# rake version:bump:patch -> increase version and add a git-tag
|
20
|
+
begin
|
21
|
+
require 'jeweler'
|
22
|
+
rescue LoadError => e
|
23
|
+
$stderr.puts "Jeweler, or one of its dependencies, is not available:"
|
24
|
+
$stderr.puts "#{e.class}: #{e.message}"
|
25
|
+
$stderr.puts "Install it with: sudo gem install jeweler"
|
26
|
+
else
|
27
|
+
Jeweler::Tasks.new do |gem|
|
28
|
+
gem.name = 'bovespa_ingestion'
|
29
|
+
gem.summary = "An importer of historical quotations from BM&F Bovespa"
|
30
|
+
gem.email = "seixasfelipe@gmail.com"
|
31
|
+
gem.homepage = "http://github.com/seixasfelipe/bovespa-ingestion"
|
32
|
+
gem.authors = ["Felipe Seixas", "Rodrigo Fraga"]
|
33
|
+
end
|
34
|
+
|
35
|
+
Jeweler::GemcutterTasks.new
|
36
|
+
end
|
37
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
Binary file
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
3
|
+
require 'historico_ativos'
|
4
|
+
|
5
|
+
module HistoricoAtivos
|
6
|
+
|
7
|
+
sample_file = 'sample/sample_cota_hist_2003.txt'
|
8
|
+
sample_file = ARGV[0] if ARGV.size > 0
|
9
|
+
|
10
|
+
puts "Carregando historico do arquivo: #{sample_file}"
|
11
|
+
|
12
|
+
start_time = Time.now
|
13
|
+
|
14
|
+
loader = CarregaHistorico.new ParserHeader.new, ParserTrailer.new, ParserAtivo.new
|
15
|
+
historico = loader.load sample_file
|
16
|
+
loader.persist historico
|
17
|
+
|
18
|
+
end_time = Time.now
|
19
|
+
elapsed_time = (end_time - start_time) * 1000.0
|
20
|
+
|
21
|
+
puts "Historico carregado em #{elapsed_time} ms!"
|
22
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{bovespa_ingestion}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Felipe Seixas", "Rodrigo Fraga"]
|
12
|
+
s.date = %q{2011-12-26}
|
13
|
+
s.default_executable = %q{carregar_historico}
|
14
|
+
s.email = %q{seixasfelipe@gmail.com}
|
15
|
+
s.executables = ["carregar_historico"]
|
16
|
+
s.extra_rdoc_files = [
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
"Gemfile",
|
21
|
+
"Gemfile.lock",
|
22
|
+
"README.md",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"archives/SeriesHistoricas_Layout.pdf",
|
26
|
+
"bin/carregar_historico",
|
27
|
+
"bovespa_ingestion.gemspec",
|
28
|
+
"config/environment.rb",
|
29
|
+
"db/config.yml",
|
30
|
+
"db/migrate/20111221001450_create_historico.rb",
|
31
|
+
"db/migrate/20111222192119_create_ativos.rb",
|
32
|
+
"db/migrate/20111223004105_change_ativos.rb",
|
33
|
+
"db/migrate/20111223023840_add_quantidade_ativos_to_historico_ativos.rb",
|
34
|
+
"db/migrate/20111223131703_add_prazo_termo_to_ativo.rb",
|
35
|
+
"db/migrate/20111223213342_alter_reference_historico_ativo.rb",
|
36
|
+
"db/migrate/20111223214919_remove_data_importacao.rb",
|
37
|
+
"db/schema.rb",
|
38
|
+
"lib/historico_ativos.rb",
|
39
|
+
"lib/historico_ativos/ativo.rb",
|
40
|
+
"lib/historico_ativos/carrega_historico.rb",
|
41
|
+
"lib/historico_ativos/header.rb",
|
42
|
+
"lib/historico_ativos/historico.rb",
|
43
|
+
"lib/historico_ativos/parser_ativo.rb",
|
44
|
+
"lib/historico_ativos/parser_header.rb",
|
45
|
+
"lib/historico_ativos/parser_trailer.rb",
|
46
|
+
"lib/historico_ativos/trailer.rb",
|
47
|
+
"sample/DemoCotacoesHistoricas12022003.txt",
|
48
|
+
"sample/sample_cota_hist_2003.txt",
|
49
|
+
"spec/historico_ativos/ativo_spec.rb",
|
50
|
+
"spec/historico_ativos/carrega_historico_spec.rb",
|
51
|
+
"spec/historico_ativos/historico_spec.rb",
|
52
|
+
"spec/historico_ativos/parser_ativo_spec.rb",
|
53
|
+
"spec/historico_ativos/parser_header_spec.rb",
|
54
|
+
"spec/historico_ativos/parser_trailer_spec.rb",
|
55
|
+
"spec/spec_helper.rb"
|
56
|
+
]
|
57
|
+
s.homepage = %q{http://github.com/seixasfelipe/bovespa-ingestion}
|
58
|
+
s.require_paths = ["lib"]
|
59
|
+
s.rubygems_version = %q{1.6.2}
|
60
|
+
s.summary = %q{An importer of historical quotations from BM&F Bovespa}
|
61
|
+
|
62
|
+
if s.respond_to? :specification_version then
|
63
|
+
s.specification_version = 3
|
64
|
+
|
65
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
66
|
+
s.add_runtime_dependency(%q<rake>, [">= 0"])
|
67
|
+
s.add_runtime_dependency(%q<activerecord>, [">= 3"])
|
68
|
+
s.add_runtime_dependency(%q<standalone_migrations>, [">= 0"])
|
69
|
+
else
|
70
|
+
s.add_dependency(%q<rake>, [">= 0"])
|
71
|
+
s.add_dependency(%q<activerecord>, [">= 3"])
|
72
|
+
s.add_dependency(%q<standalone_migrations>, [">= 0"])
|
73
|
+
end
|
74
|
+
else
|
75
|
+
s.add_dependency(%q<rake>, [">= 0"])
|
76
|
+
s.add_dependency(%q<activerecord>, [">= 3"])
|
77
|
+
s.add_dependency(%q<standalone_migrations>, [">= 0"])
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
data/db/config.yml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
development:
|
2
|
+
adapter: sqlite3
|
3
|
+
database: db/development.sqlite3
|
4
|
+
pool: 5
|
5
|
+
timeout: 5000
|
6
|
+
|
7
|
+
production:
|
8
|
+
adapter: mysql
|
9
|
+
encoding: utf8
|
10
|
+
reconnect: false
|
11
|
+
database: somedatabase_dev
|
12
|
+
pool: 5
|
13
|
+
username: root
|
14
|
+
password:
|
15
|
+
socket: /var/run/mysqld/mysqld.sock
|
16
|
+
|
17
|
+
test: &test
|
18
|
+
adapter: sqlite3
|
19
|
+
database: db/test.sqlite3
|
20
|
+
pool: 5
|
21
|
+
timeout: 5000
|
22
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class CreateHistorico < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :historico_ativos do |t|
|
4
|
+
t.string :nome_arquivo
|
5
|
+
t.string :codigo_origem
|
6
|
+
t.date :data_geracao
|
7
|
+
t.date :data_importacao
|
8
|
+
t.timestamps
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.down
|
13
|
+
drop_table :historico_ativos
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class CreateAtivos < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :ativos do |t|
|
4
|
+
t.date :data
|
5
|
+
t.string :codigo_bdi
|
6
|
+
t.string :codigo
|
7
|
+
t.string :tipo_mercado
|
8
|
+
t.string :nome
|
9
|
+
t.string :especificacao
|
10
|
+
t.string :moeda_referencia
|
11
|
+
t.decimal :preco_abertura
|
12
|
+
t.decimal :preco_maximo
|
13
|
+
t.decimal :preco_minimo
|
14
|
+
t.decimal :preco_medio
|
15
|
+
t.decimal :preco_ultimo
|
16
|
+
t.decimal :preco_melhor_oferta_compra
|
17
|
+
t.decimal :preco_melhor_oferta_venda
|
18
|
+
t.decimal :total_negocios
|
19
|
+
t.decimal :quantidade_titulos_negociados
|
20
|
+
t.decimal :volume_negocios
|
21
|
+
t.timestamps
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.down
|
26
|
+
drop_table :ativos
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class AlterReferenceHistoricoAtivo < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
remove_index :ativos, :historico_ativo_id
|
4
|
+
rename_column :ativos, :historico_ativo_id, :historico_id
|
5
|
+
add_index :ativos, :historico_id
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.down
|
9
|
+
remove_index :ativos, :historico_id
|
10
|
+
rename_column :ativos, :historico_id, :historico_ativo_id
|
11
|
+
add_index :ativos, :historico_ativo_id
|
12
|
+
end
|
13
|
+
end
|
data/db/schema.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# This file is auto-generated from the current state of the database. Instead
|
3
|
+
# of editing this file, please use the migrations feature of Active Record to
|
4
|
+
# incrementally modify your database, and then regenerate this schema definition.
|
5
|
+
#
|
6
|
+
# Note that this schema.rb definition is the authoritative source for your
|
7
|
+
# database schema. If you need to create the application database on another
|
8
|
+
# system, you should be using db:schema:load, not running all the migrations
|
9
|
+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
10
|
+
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
11
|
+
#
|
12
|
+
# It's strongly recommended to check this file into your version control system.
|
13
|
+
|
14
|
+
ActiveRecord::Schema.define(:version => 20111223214919) do
|
15
|
+
|
16
|
+
create_table "ativos", :force => true do |t|
|
17
|
+
t.date "data"
|
18
|
+
t.string "codigo_bdi"
|
19
|
+
t.string "codigo"
|
20
|
+
t.string "tipo_mercado"
|
21
|
+
t.string "nome"
|
22
|
+
t.string "especificacao"
|
23
|
+
t.string "moeda_referencia"
|
24
|
+
t.decimal "preco_abertura"
|
25
|
+
t.decimal "preco_maximo"
|
26
|
+
t.decimal "preco_minimo"
|
27
|
+
t.decimal "preco_medio"
|
28
|
+
t.decimal "preco_ultimo"
|
29
|
+
t.decimal "preco_melhor_oferta_compra"
|
30
|
+
t.decimal "preco_melhor_oferta_venda"
|
31
|
+
t.decimal "total_negocios"
|
32
|
+
t.decimal "quantidade_titulos_negociados"
|
33
|
+
t.decimal "volume_negocios"
|
34
|
+
t.datetime "created_at"
|
35
|
+
t.datetime "updated_at"
|
36
|
+
t.integer "historico_id"
|
37
|
+
t.integer "prazo_termo"
|
38
|
+
end
|
39
|
+
|
40
|
+
add_index "ativos", ["historico_id"], :name => "index_ativos_on_historico_id"
|
41
|
+
|
42
|
+
create_table "historico_ativos", :force => true do |t|
|
43
|
+
t.string "nome_arquivo"
|
44
|
+
t.string "codigo_origem"
|
45
|
+
t.date "data_geracao"
|
46
|
+
t.datetime "created_at"
|
47
|
+
t.datetime "updated_at"
|
48
|
+
t.integer "quantidade_ativos"
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module HistoricoAtivos
|
2
|
+
class CarregaHistorico
|
3
|
+
|
4
|
+
attr_accessor :parser_header, :parser_trailer, :parser_ativo
|
5
|
+
|
6
|
+
def initialize(parser_header, parser_trailer, parser_ativo)
|
7
|
+
@parser_header = parser_header
|
8
|
+
@parser_trailer = parser_trailer
|
9
|
+
@parser_ativo = parser_ativo
|
10
|
+
end
|
11
|
+
|
12
|
+
def load(filepath)
|
13
|
+
return false unless File.exists?(filepath)
|
14
|
+
|
15
|
+
file = File.open(filepath, "r")
|
16
|
+
|
17
|
+
historico = Historico.new
|
18
|
+
|
19
|
+
file.each { |line|
|
20
|
+
historico.import_header @parser_header.parse(line) if line.start_with?("00")
|
21
|
+
historico.ativos << @parser_ativo.parse(line) if line.start_with?("01")
|
22
|
+
historico.import_trailer @parser_trailer.parse(line) if line.start_with?("99")
|
23
|
+
}
|
24
|
+
|
25
|
+
historico
|
26
|
+
end
|
27
|
+
|
28
|
+
def persist(historico)
|
29
|
+
historico.save
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module HistoricoAtivos
|
2
|
+
class Historico < ActiveRecord::Base
|
3
|
+
set_table_name "historico_ativos"
|
4
|
+
|
5
|
+
has_many :ativos
|
6
|
+
|
7
|
+
def import_header(header)
|
8
|
+
self.nome_arquivo = header.nome_arquivo
|
9
|
+
self.data_geracao = header.data_geracao
|
10
|
+
self.codigo_origem = header.codigo_origem
|
11
|
+
end
|
12
|
+
|
13
|
+
def import_trailer(trailer)
|
14
|
+
self.quantidade_ativos = trailer.quantidade_ativos
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'bigdecimal'
|
3
|
+
|
4
|
+
module HistoricoAtivos
|
5
|
+
class ParserAtivo
|
6
|
+
def parse(row)
|
7
|
+
read_ativo(row) if row.start_with?("01")
|
8
|
+
end
|
9
|
+
|
10
|
+
def read_ativo(row)
|
11
|
+
ativo = Ativo.new
|
12
|
+
ativo.data = read_data row
|
13
|
+
ativo.codigo_bdi = read_codigo_bdi row
|
14
|
+
ativo.codigo = read_codigo row
|
15
|
+
ativo.tipo_mercado = read_tipo_mercado row
|
16
|
+
ativo.nome = read_nome row
|
17
|
+
ativo.especificacao = read_especificacao row
|
18
|
+
ativo.prazo_termo = read_prazo_termo row
|
19
|
+
ativo.moeda_referencia = read_moeda_referencia row
|
20
|
+
ativo.preco_abertura = read_preco_abertura row
|
21
|
+
ativo.preco_maximo = read_preco_maximo row
|
22
|
+
ativo.preco_minimo = read_preco_minimo row
|
23
|
+
ativo.preco_medio = read_preco_medio row
|
24
|
+
ativo.preco_ultimo = read_preco_ultimo row
|
25
|
+
ativo.preco_melhor_oferta_compra = read_preco_melhor_oferta_compra row
|
26
|
+
ativo.preco_melhor_oferta_venda = read_preco_melhor_oferta_venda row
|
27
|
+
ativo.total_negocios = read_total_negocios row
|
28
|
+
ativo.quantidade_titulos_negociados= read_quantidade_titulos_negociados row
|
29
|
+
ativo.volume_negocios = read_volume_negocios row
|
30
|
+
ativo
|
31
|
+
end
|
32
|
+
|
33
|
+
def read_data(row)
|
34
|
+
year = row[2..5]
|
35
|
+
month = row[6..7]
|
36
|
+
day = row[8..9]
|
37
|
+
Date.new(year.to_i, month.to_i, day.to_i)
|
38
|
+
end
|
39
|
+
|
40
|
+
def read_codigo_bdi(row)
|
41
|
+
row[10..11].to_i
|
42
|
+
end
|
43
|
+
|
44
|
+
def read_codigo(row)
|
45
|
+
row[12..23].strip
|
46
|
+
end
|
47
|
+
|
48
|
+
def read_tipo_mercado(row)
|
49
|
+
row[24..26].to_i
|
50
|
+
end
|
51
|
+
|
52
|
+
def read_nome(row)
|
53
|
+
row[27..38].strip
|
54
|
+
end
|
55
|
+
|
56
|
+
def read_especificacao(row)
|
57
|
+
row[39..48].strip
|
58
|
+
end
|
59
|
+
|
60
|
+
def read_prazo_termo(row)
|
61
|
+
row[49..51].to_i
|
62
|
+
end
|
63
|
+
|
64
|
+
def read_moeda_referencia(row)
|
65
|
+
row[52..55].strip
|
66
|
+
end
|
67
|
+
|
68
|
+
def read_preco_abertura(row)
|
69
|
+
converts_to_big_decimal row[56..68].to_i
|
70
|
+
end
|
71
|
+
|
72
|
+
def read_preco_maximo(row)
|
73
|
+
converts_to_big_decimal row[69..81].to_i
|
74
|
+
end
|
75
|
+
|
76
|
+
def read_preco_minimo(row)
|
77
|
+
converts_to_big_decimal row[82..94].to_i
|
78
|
+
end
|
79
|
+
|
80
|
+
def read_preco_medio(row)
|
81
|
+
converts_to_big_decimal row[95..107].to_i
|
82
|
+
end
|
83
|
+
|
84
|
+
def read_preco_ultimo(row)
|
85
|
+
converts_to_big_decimal row[108..120].to_i
|
86
|
+
end
|
87
|
+
|
88
|
+
def read_preco_melhor_oferta_compra(row)
|
89
|
+
converts_to_big_decimal row[121..133].to_i
|
90
|
+
end
|
91
|
+
|
92
|
+
def read_preco_melhor_oferta_venda(row)
|
93
|
+
converts_to_big_decimal row[134..146].to_i
|
94
|
+
end
|
95
|
+
|
96
|
+
def read_total_negocios(row)
|
97
|
+
row[147..151].to_i
|
98
|
+
end
|
99
|
+
|
100
|
+
def read_quantidade_titulos_negociados(row)
|
101
|
+
BigDecimal.new(row[152..169])
|
102
|
+
end
|
103
|
+
|
104
|
+
def read_volume_negocios(row)
|
105
|
+
BigDecimal.new(row[170..187])
|
106
|
+
end
|
107
|
+
|
108
|
+
def converts_to_big_decimal(preco)
|
109
|
+
preco_s = preco.to_s
|
110
|
+
preco_s.insert(preco_s.size - 2, '.')
|
111
|
+
BigDecimal.new(preco_s)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
module HistoricoAtivos
|
4
|
+
class ParserHeader
|
5
|
+
def parse(row)
|
6
|
+
read_header row if row.start_with?("00")
|
7
|
+
end
|
8
|
+
|
9
|
+
def read_header(row)
|
10
|
+
header = Header.new
|
11
|
+
header.nome_arquivo = read_nome_arquivo row
|
12
|
+
header.codigo_origem = read_codigo_origem row
|
13
|
+
header.data_geracao = read_data_geracao row
|
14
|
+
header
|
15
|
+
end
|
16
|
+
|
17
|
+
def read_nome_arquivo(row)
|
18
|
+
row[02..14].strip
|
19
|
+
end
|
20
|
+
|
21
|
+
def read_codigo_origem(row)
|
22
|
+
row[15..22].strip
|
23
|
+
end
|
24
|
+
|
25
|
+
def read_data_geracao(row)
|
26
|
+
year = row[23..26]
|
27
|
+
month = row[27..28]
|
28
|
+
day = row[29..30]
|
29
|
+
Date.new(year.to_i, month.to_i, day.to_i)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module HistoricoAtivos
|
2
|
+
class ParserTrailer
|
3
|
+
def parse(row)
|
4
|
+
read_trailer row if row.start_with?("99")
|
5
|
+
end
|
6
|
+
|
7
|
+
def read_trailer(row)
|
8
|
+
trailer = Trailer.new
|
9
|
+
trailer.quantidade_ativos = read_quantidade_ativos row
|
10
|
+
trailer
|
11
|
+
end
|
12
|
+
|
13
|
+
def read_quantidade_ativos(row)
|
14
|
+
total = row[31..41].to_i
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|