Class: I18nAdmin::Import::XLS
Constant Summary collapse
- PAGINATION_PATTERN =
Used to split cells with large content
/\(\d+ \/ (\d+)\)$/
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#sheet ⇒ Object
readonly
Returns the value of attribute sheet.
-
#spreadsheet ⇒ Object
readonly
Returns the value of attribute spreadsheet.
Attributes inherited from Base
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(locale, file) ⇒ XLS
constructor
A new instance of XLS.
- #run ⇒ Object
Methods inherited from Base
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
#file ⇒ Object (readonly)
Returns the value of attribute file.
9 10 11 |
# File 'lib/i18n_admin/import/xls.rb', line 9 def file @file end |
#sheet ⇒ Object (readonly)
Returns the value of attribute sheet.
9 10 11 |
# File 'lib/i18n_admin/import/xls.rb', line 9 def sheet @sheet end |
#spreadsheet ⇒ Object (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
#run ⇒ Object
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 |