Class: BrazilianFinancialIndexes::Input

Inherits:
Object
  • Object
show all
Defined in:
lib/brazilian_financial_indexes/input.rb

Constant Summary collapse

INDEX_DOWNLOADER_BIN =
Pathname("bin/Download_Indices.exe").to_s
OUTPUT =
"Indic.txt"

Class Method Summary collapse

Class Method Details

.create_fileObject



6
7
8
9
10
# File 'lib/brazilian_financial_indexes/input.rb', line 6

def self.create_file
  prefix = RUBY_PLATFORM.match(/linux/) ? "wine" : ""
  File.delete(OUTPUT) if File.exists?(OUTPUT)
  system("#{prefix} #{INDEX_DOWNLOADER_BIN}")
end

.parse_fileObject



12
13
14
15
16
17
18
# File 'lib/brazilian_financial_indexes/input.rb', line 12

def self.parse_file
  lines = File.readlines(OUTPUT).map do |line|
    date = Date.parse(line[11..18])
    value = parse_value(line)
    { date: date, importing_code: line[19..45].strip, value: value }
  end.compact
end