Class: OfficeCSV

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

Class Method Summary collapse

Class Method Details

.generate(&block) ⇒ Object

Works just like FasterCSV.generate. It adds a byte order mark to the beginning of the document and converts the contents from UTF-8 to UTF-16LE.



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

def self.generate(&block)
  [0xff, 0xfe].pack('C*') + Iconv.iconv('UTF-16LE', 'UTF-8',
    FasterCSV.generate(:col_sep => "\t", &block)
  ).join
end

.parse(csv) ⇒ Object

Just like FastCSV.parse. It removes the byte order mark and transcodes from UTF-16LE to UTF-8.



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

def self.parse(csv)
  FasterCSV.parse(Iconv.iconv('UTF-8', 'UTF-16LE', csv).first[3..-1], :col_sep => "\t")
end