Sha256: 7b9440a6eb7a6161278c474e9d8c938b5cbd8f9fe9e3c4a221d43a6d1e3b0ac6

Contents?: true

Size: 635 Bytes

Versions: 76

Compression:

Stored size: 635 Bytes

Contents

# encoding: utf-8

# File
class File
  # insert BOM to UTF-8 File
  #
  # this method's main purpose is 'UTF-8 Excel CSV File'.
  #
  # File.insert_bom("input.csv", "output.csv") # => output bommed text to output.csv
  # File.insert_bom("input.csv") # => output bommed text to input.csv
  def self.insert_bom(input_filename, output_filename = nil)
    src = File.read(input_filename)
    output_filename ||= input_filename
    File.open(output_filename, 'w:UTF-8') do |f|
      src = '   ' + src
      src.setbyte(0, 0xEF)
      src.setbyte(1, 0xBB)
      src.setbyte(2, 0xBF)
      f.print src
    end
  end
end

Version data entries

76 entries across 76 versions & 1 rubygems

Version Path
tbpgr_utils-0.0.43 lib/open_classes/file.rb
tbpgr_utils-0.0.42 lib/open_classes/file.rb
tbpgr_utils-0.0.41 lib/open_classes/file.rb
tbpgr_utils-0.0.40 lib/open_classes/file.rb
tbpgr_utils-0.0.39 lib/open_classes/file.rb
tbpgr_utils-0.0.38 lib/open_classes/file.rb
tbpgr_utils-0.0.37 lib/open_classes/file.rb
tbpgr_utils-0.0.36 lib/open_classes/file.rb
tbpgr_utils-0.0.35 lib/open_classes/file.rb
tbpgr_utils-0.0.34 lib/open_classes/file.rb
tbpgr_utils-0.0.33 lib/open_classes/file.rb
tbpgr_utils-0.0.32 lib/open_classes/file.rb
tbpgr_utils-0.0.31 lib/open_classes/file.rb
tbpgr_utils-0.0.30 lib/open_classes/file.rb
tbpgr_utils-0.0.29 lib/open_classes/file.rb
tbpgr_utils-0.0.28 lib/open_classes/file.rb