Class: SuperSpreadsheet::Loader

Inherits:
SuperProcess::Core show all
Defined in:
lib/super_spreadsheet/loader.rb

Constant Summary

Constants inherited from SuperProcess::Core

SuperProcess::Core::CALLBACK_CALL, SuperProcess::Core::CALLBACK_TASK, SuperProcess::Core::ValidError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SuperProcess::Core

after_call, after_task, before_call, before_task, callable, #error_message, #error_messages, init, #result

Constructor Details

#initialize(file_path) ⇒ Loader

Returns a new instance of Loader.



14
15
16
# File 'lib/super_spreadsheet/loader.rb', line 14

def initialize(file_path)
  @file_path = file_path
end

Instance Attribute Details

#file_pathObject

Returns the value of attribute file_path.



7
8
9
# File 'lib/super_spreadsheet/loader.rb', line 7

def file_path
  @file_path
end

Class Method Details

.load!(file) ⇒ Object



10
11
12
# File 'lib/super_spreadsheet/loader.rb', line 10

def self.load!(file)
  new(file)
end

Instance Method Details

#extensionObject



22
23
24
# File 'lib/super_spreadsheet/loader.rb', line 22

def extension
  ::File.extname(file_path).split(".").last.force_encoding("utf-8").downcase
end

#rowsObject



34
35
36
# File 'lib/super_spreadsheet/loader.rb', line 34

def rows
  @rows ||= rows!
end

#valid_formatObject



26
27
28
29
30
31
32
# File 'lib/super_spreadsheet/loader.rb', line 26

def valid_format
  if rows == false
    errors.add(:file, "檔案格式錯誤")
  elsif rows.flatten.empty?
    errors.add(:file, "檔案內容錯誤,空白檔案")
  end
end