-
Notifications
You must be signed in to change notification settings - Fork 2
/
current_state.rb
35 lines (30 loc) · 940 Bytes
/
current_state.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
require 'yaml'
require_relative 'statements_dashboard'
require_relative 'raw_data_parser'
module BancoDoBrasil
class CurrentState
def initialize
credentials = YAML.load_file(File.expand_path('../config/credentials.yml', __FILE__))
@branch = credentials['branch']
@account = credentials['account']
@password = credentials['password']
end
def perform
data = StatementsDashboard.new(@branch, @account, @password).fetch_all
data.map do |tuple|
uuid = save_raw(tuple)
tuple[1]['id'] = uuid
RawDataParser.new(*tuple).as_json
end.flatten
end
private
def save_raw(tuple)
uuid = SecureRandom.uuid
file_name = File.expand_path("../data/#{tuple[0]}/#{uuid}.json", __FILE__)
folder = File.dirname(file_name)
Dir.exist?(folder) or FileUtils.mkdir_p(folder)
File.write(file_name, tuple[1].to_json)
uuid
end
end
end