Class: Vaultify::VaultifyController
Instance Method Summary
collapse
Methods included from EdtfHelper
#add_separators, #add_zeroes, #arrange, #clean_extra_words, #clean_words, #convert_date, #d2, #d4, #descriptors, #dirty, #machine_clean, #months, #rearrange, #scrub, #seasons
Constructor Details
Returns a new instance of VaultifyController.
10
11
12
13
|
# File 'app/controllers/vaultify/vaultify_controller.rb', line 10
def initialize
super
@fields = Vaultify::Engine.config['fields']
end
|
Instance Method Details
#aat ⇒ Object
89
90
91
92
93
94
95
96
|
# File 'app/controllers/vaultify/vaultify_controller.rb', line 89
def aat
res = aatApi params['cleanQuery']
respond_to do |format|
format.xml {render plain: res}
format.text {render plain: res}
format.json {render plain: res.to_json}
end
end
|
#edtf ⇒ Object
98
99
100
101
102
103
|
# File 'app/controllers/vaultify/vaultify_controller.rb', line 98
def edtf
date = convert_date params[:query]
respond_to do |format|
format.text {render plain: date}
end
end
|
#export ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'app/controllers/vaultify/vaultify_controller.rb', line 46
def export
path = Rails.root.join('public', 'csvs', 'upload', params[:csv_name])
@csv = ::CSV.parse(File.read(path), headers: true, encoding: 'utf-8').map(&:to_hash)
@puramses = params
@fields.each do |field_row|
next unless params.key? field_row.first.to_sym
params.permit![field_row.first.to_sym].each do |csv_row, values|
adj = []
values.each do |_, value|
adj << value
end
@csv[csv_row.to_i][field_row.first] = adj.join('|')
end
end
csv_output = []
csv_output << @csv.first.keys
@csv.each do |row|
csv_output << row.values
end
respond_to do |format|
format.csv {render plain: csv_output.inject([]) {|csv, row| csv << CSV.generate_line(row)}.join, content_type: 'text/csv'}
end
end
|
#fast ⇒ Object
80
81
82
83
84
85
86
87
|
# File 'app/controllers/vaultify/vaultify_controller.rb', line 80
def fast
res = fastApi params['query']
respond_to do |format|
format.json {render plain: res}
format.text {render plain: res}
end
end
|
#translate ⇒ Object
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
|
# File 'app/controllers/vaultify/vaultify_controller.rb', line 19
def translate
@mvs = Vaultify::Engine.config['mvs']
csv = params['csv'].path
@csv = ::CSV.parse(File.read(csv), headers: true, encoding: 'utf-8').map(&:to_hash)
@csv_name = params[:csv].original_filename.gsub '.csv', ''
@csv_name += Time.now.strftime('%Y%m%d%H%M%S%L') + '.csv'
csv_path = Rails.root.join('public', 'csvs', 'upload')
FileUtils.mkdir_p(csv_path) unless File.directory? csv_path
File.open(File.join(csv_path, @csv_name), 'wb') {|f| f.write(File.read(csv))}
@total = @csv.length
@csv.each_with_index do |row, index|
next if row.nil?
@fields.each do |field_row|
field = field_row.first
api = field_row.last
next if row[field].to_s.empty? || api.to_s.empty?
adjusted_array = []
row[field].split(@mvs).each do |line|
adjusted_array << send("#{api}First", line) rescue nil
end
@csv[index]["#{field}-adjusted"] = adjusted_array.join(@mvs)
end
end
end
|
#upload ⇒ Object
15
16
17
|
# File 'app/controllers/vaultify/vaultify_controller.rb', line 15
def upload
end
|