Module: Decidim::Admin::Import::Readers

Defined in:
lib/decidim/admin/import/readers.rb,
lib/decidim/admin/import/readers/csv.rb,
lib/decidim/admin/import/readers/base.rb,
lib/decidim/admin/import/readers/json.rb,
lib/decidim/admin/import/readers/xlsx.rb

Defined Under Namespace

Classes: Base, CSV, JSON, XLSX

Constant Summary collapse

ACCEPTED_MIME_TYPES =

Accepted mime types keys: are used for dynamic help text on admin form. values: are used to validate the file format of imported document.

{
  csv: Readers::CSV::MIME_TYPE,
  json: Readers::JSON::MIME_TYPE,
  xlsx: Readers::XLSX::MIME_TYPE
}.freeze

Class Method Summary collapse

Class Method Details

.allObject



21
22
23
24
25
26
27
# File 'lib/decidim/admin/import/readers.rb', line 21

def self.all
  [
    Readers::CSV,
    Readers::JSON,
    Readers::XLSX
  ]
end

.search_by_file_extension(extension) ⇒ Object



37
38
39
40
41
# File 'lib/decidim/admin/import/readers.rb', line 37

def self.search_by_file_extension(extension)
  return unless ACCEPTED_MIME_TYPES.has_key?(extension.to_sym)

  search_by_mime_type(ACCEPTED_MIME_TYPES[extension.to_sym])
end

.search_by_mime_type(mime_type) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/decidim/admin/import/readers.rb', line 29

def self.search_by_mime_type(mime_type)
  all.each do |reader_klass|
    return reader_klass if mime_type == reader_klass::MIME_TYPE
  end

  nil
end