Class: CvList

Inherits:
Object
  • Object
show all
Includes:
CrudHelpers
Defined in:
backend/app/lib/bulk_import/cv_list.rb

Instance Method Summary collapse

Methods included from CrudHelpers

#handle_create, #handle_delete, #handle_listing, #handle_raw_listing, #handle_unlimited_listing, #handle_update, scoped_dataset, with_record_conflict_reporting, #with_record_conflict_reporting

Constructor Details

#initialize(which, current_user) ⇒ CvList

Returns a new instance of CvList.



13
14
15
16
17
# File 'backend/app/lib/bulk_import/cv_list.rb', line 13

def initialize(which, current_user)
  @which = which
  @current_user = current_user
  renew
end

Instance Method Details

#lengthObject



29
30
31
# File 'backend/app/lib/bulk_import/cv_list.rb', line 29

def length
  @list.length
end

#renewObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'backend/app/lib/bulk_import/cv_list.rb', line 33

def renew
  @list = []
  list_hash = {}
  enums = handle_raw_listing(Enumeration, { :name => @which }, @current_user)
  enums[0]["values"].each do |v|
    if !v["suppressed"]
      trans = I18n.t("enumerations.#{@which}.#{v}", default: v)
      if !list_hash[trans]
        list_hash[trans] = v
        @list.push v
      else
        Log.warn(I18n.t("bulk_import.warn.dup", :which => @which, :trans => trans, :used => list_hash[trans]))
      end
    end
  end
  @list_hash = list_hash
end

#value(label) ⇒ Object

Raises:

  • (Exception)


19
20
21
22
23
24
25
26
27
# File 'backend/app/lib/bulk_import/cv_list.rb', line 19

def value(label)
  if @list_hash[label]
    v = @list_hash[label]
  elsif @list.index(label)
    v = label
  end
  raise Exception.new(I18n.t("bulk_import.error.enum", :label => label, :which => @which)) if !v
  v
end