forked from jazzido/presu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
53 lines (39 loc) · 1.42 KB
/
Rakefile
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
require 'rake'
require 'rake/tasklib'
require_relative './model'
require 'dm-migrations'
require 'csv'
namespace :presu do
desc "migrate the db"
task :migrate do
DataMapper.auto_migrate!
end
desc "upgrade the db"
task :upgrade do
DataMapper.auto_upgrade!
end
desc "import data"
task :import do
CSV.foreach(ENV['DATA'] || 'data.csv', :headers => :first_row) do |row|
j = Jurisdiccion.first_or_create(:id => row['JURISDICCION #'], :nombre => row['JURISDICCION'])
c = Caracter.first_or_create(:id => row['CARACTER #'], :nombre => row['CARACTER'])
s = Servicio.first_or_new(:id => row['SERVICIO #'],
:nombre => row['SERVICIO'])
puts "Servicio: #{row['SERVICIO #']}, #{row['SERVICIO']}"
s.jurisdiccion = j; s.caracter = c
s.save
# p = Programa.first_or_new(:id => row['PROGRAMA'].split(' - ')[0],
# :nombre => row['PROGRAMA'].split(' - ')[1])
# p.servicio = s
# p.save
r = Registro.new(:fecha => Date.strptime(row['FECHA'], '%m/%d/%Y'),
:credito => row['CREDITO'].to_f,
:compromiso => row['COMPROMISO'].to_f,
:devengado => row['DEVENGADO'].to_f,
:pagado => row['PAGADO'].to_f,
:programa_name => row['PROGRAMA'].split(' - ')[1])
r.servicio = s
r.save
end
end
end