Class: Importo::ImportColumn

Inherits:
Object
  • Object
show all
Defined in:
lib/importo/import_column.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name: nil, **options, &block) ⇒ ImportColumn

Returns a new instance of ImportColumn.



8
9
10
11
12
13
14
# File 'lib/importo/import_column.rb', line 8

def initialize(name: nil, **options, &block)
  @name = name
  @hint = options[:hint]
  @explanation = options[:explanation]
  @options = options || {}
  @proc = block
end

Instance Attribute Details

#exampleObject



47
48
49
# File 'lib/importo/import_column.rb', line 47

def example
  I18n.t(".example.#{options[:attribute]}", scope: [:importers, options[:scope]], default: "") if options[:attribute]
end

#explanationObject



39
40
41
# File 'lib/importo/import_column.rb', line 39

def explanation
  I18n.t(".explanation.#{options[:attribute]}", scope: [:importers, options[:scope]], default: "") if options[:attribute]
end

#hintObject



35
36
37
# File 'lib/importo/import_column.rb', line 35

def hint
  I18n.t(".hint.#{options[:attribute]}", scope: [:importers, options[:scope]], default: "") if options[:attribute]
end

#nameObject



20
21
22
23
# File 'lib/importo/import_column.rb', line 20

def name
  name = options[:attribute] || @name
  I18n.t(".column.#{name}", scope: [:importers, options[:scope]], default: name)
end

#optionsObject

Returns the value of attribute options.



5
6
7
# File 'lib/importo/import_column.rb', line 5

def options
  @options
end

#procObject

Returns the value of attribute proc.



5
6
7
# File 'lib/importo/import_column.rb', line 5

def proc
  @proc
end

#valueObject



43
44
45
# File 'lib/importo/import_column.rb', line 43

def value
  I18n.t(".value.#{options[:attribute]}", scope: [:importers, options[:scope]], default: "") if options[:attribute]
end

Instance Method Details

#allowed_namesObject



25
26
27
28
29
30
31
32
33
# File 'lib/importo/import_column.rb', line 25

def allowed_names
  return @allowed_names if @allowed_names.present?

  name = options[:attribute] || @name

  @allowed_names = I18n.available_locales.map do |locale|
    I18n.t(".column.#{name}", scope: [:importers, options[:scope]], locale: locale, default: name)
  end.compact.uniq
end

#attributeObject



16
17
18
# File 'lib/importo/import_column.rb', line 16

def attribute
  options[:attribute] || @name
end

#collectionObject

Collection of values (name, id) that are valid for this field, if a name is entered it will be replaced by the id during pre-processing



59
60
61
# File 'lib/importo/import_column.rb', line 59

def collection
  options[:collection]
end

#delayObject



63
64
65
# File 'lib/importo/import_column.rb', line 63

def delay
  options[:delay]
end

#overridable?Boolean

If set this allows the user to set a value during upload that overrides the uploaded values.

Returns:

  • (Boolean)


53
54
55
# File 'lib/importo/import_column.rb', line 53

def overridable?
  options[:overridable]
end