Class: Safai::Spreadsheet

Inherits:
Object
  • Object
show all
Defined in:
lib/safai/spreadsheet.rb

Class Method Summary collapse

Class Method Details

.is_excel?(data_file_name) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/safai/spreadsheet.rb', line 13

def self.is_excel?(data_file_name)
  return (!data_file_name.index(".xls").nil? or !data_file_name.index(".ods").nil? or !data_file_name.index(".csv").nil?) ? true : false
end

.open(url, data_file_name, domain) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/safai/spreadsheet.rb', line 17

def self.open(url, data_file_name, domain)
  begin
    url_s = url.to_s.gsub(domain, "")
    case File.extname(data_file_name)
      when ".csv" then  s = Csv.new(url_s, nil, :ignore)
      when ".xls" then  s = Excel.new(url_s, nil, :ignore)
      when ".xlsx" then s = Excelx.new(url_s, nil, :ignore)
      when ".ods" then  s = Openoffice.new(url_s, nil, :ignore)
      else raise "Unknown file type: #{data_file_name}"
    end
    s.default_sheet = s.sheets.first
    return s
  rescue
    return "1"
  end
end

.process_date_from_xls(d) ⇒ Object

MICROSOFT EXCEL STORES DATES AS THE NUMBER OF DAYS FROM 1900. HENCE CONVERSION IS REQUIRED



7
8
9
10
11
# File 'lib/safai/spreadsheet.rb', line 7

def self.process_date_from_xls(d)
  return nil if d.nil?
  d = d.to_i
  return (Date.new( 1899,12,30) + d)
end