Sha256: 684798c231bc5a3a0fda72fea78b2034870c7aef6acab43922fb3287da3e83bb

Contents?: true

Size: 1.86 KB

Versions: 13

Compression:

Stored size: 1.86 KB

Contents

# frozen_string_literal: true

module Importo
  class ImportColumn
    attr_accessor :proc, :options
    attr_writer :name, :hint, :explanation, :value, :example

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

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

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

    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

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

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

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

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

    ##
    # If set this allows the user to set a value during upload that overrides the uploaded values.
    def overridable?
      options[:overridable]
    end

    ##
    # 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
    def collection
      options[:collection]
    end

    def delay
      options[:delay]
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
importo-3.0.21 lib/importo/import_column.rb
importo-3.0.20 lib/importo/import_column.rb
importo-3.0.19 lib/importo/import_column.rb
importo-3.0.18 lib/importo/import_column.rb
importo-3.0.17 lib/importo/import_column.rb
importo-3.0.16 lib/importo/import_column.rb
importo-3.0.15 lib/importo/import_column.rb
importo-3.0.14 lib/importo/import_column.rb
importo-3.0.13 lib/importo/import_column.rb
importo-3.0.12 lib/importo/import_column.rb
importo-3.0.11 lib/importo/import_column.rb
importo-3.0.10 lib/importo/import_column.rb
importo-3.0.9 lib/importo/import_column.rb