Class: Vaultify::VaultifyController

Inherits:
ApplicationController show all
Includes:
EdtfHelper
Defined in:
app/controllers/vaultify/vaultify_controller.rb

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

#initializeVaultifyController

Returns a new instance of VaultifyController.



11
12
13
14
# File 'app/controllers/vaultify/vaultify_controller.rb', line 11

def initialize
  super
  @fields = Vaultify::Engine.config['fields']
end

Instance Method Details

#aatObject



83
84
85
86
87
88
89
90
# File 'app/controllers/vaultify/vaultify_controller.rb', line 83

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

#edtfObject



92
93
94
95
96
97
# File 'app/controllers/vaultify/vaultify_controller.rb', line 92

def edtf
  date = convert_date params[:query]
  respond_to do |format|
    format.text {render plain: date}
  end
end

#exportObject



41
42
43
44
45
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
# File 'app/controllers/vaultify/vaultify_controller.rb', line 41

def export
  @csv = session[:csv].deep_dup
  @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


  #csv.each_with_index |row, index|
  #@fields.each do |field_row|
  # params[field_row.first.to_sym][index]
  #  csv
  #   end
  #end
end

#fastObject



74
75
76
77
78
79
80
81
# File 'app/controllers/vaultify/vaultify_controller.rb', line 74

def fast
  res = fastApi params['query']

  respond_to do |format|
    format.json {render plain: res}
    format.text {render plain: res}
  end
end

#translateObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/vaultify/vaultify_controller.rb', line 20

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)
  session[:csv] = ::CSV.parse(File.read(csv), headers: true, encoding: 'utf-8').map(&:to_hash)
  @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

#uploadObject



16
17
18
# File 'app/controllers/vaultify/vaultify_controller.rb', line 16

def upload

end