Class: I18nAdmin::Import::XLS

Inherits:
Base
  • Object
show all
Defined in:
lib/i18n_admin/import/xls.rb

Constant Summary collapse

PAGINATION_PATTERN =

Used to split cells with large content

/\(\d+ \/ (\d+)\)$/

Instance Attribute Summary collapse

Attributes inherited from Base

#locale

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#errors, register

Constructor Details

#initialize(locale, file) ⇒ XLS



18
19
20
21
22
# File 'lib/i18n_admin/import/xls.rb', line 18

def initialize(locale, file)
  @locale = locale
  @spreadsheet = Spreadsheet.open(file.path)
  @sheet = spreadsheet.worksheet(0)
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



9
10
11
# File 'lib/i18n_admin/import/xls.rb', line 9

def file
  @file
end

#sheetObject (readonly)

Returns the value of attribute sheet.



9
10
11
# File 'lib/i18n_admin/import/xls.rb', line 9

def sheet
  @sheet
end

#spreadsheetObject (readonly)

Returns the value of attribute spreadsheet.



9
10
11
# File 'lib/i18n_admin/import/xls.rb', line 9

def spreadsheet
  @spreadsheet
end

Class Method Details

.import(locale, file) ⇒ Object



11
12
13
14
15
16
# File 'lib/i18n_admin/import/xls.rb', line 11

def self.import(locale, file)
  import = new(locale, file)
  import.run
ensure
  file.close
end

Instance Method Details

#runObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/i18n_admin/import/xls.rb', line 24

def run
  I18n.with_locale(locale) do
    index = 0

    while (index += 1) < sheet.row_count
      key, value, index = extract_translation_at(index)
      update_translation(key, value)
    end

    save_updated_models
  end

  errors.empty?
end