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.103 lib/open_classes/file.rb
tbpgr_utils-0.0.102 lib/open_classes/file.rb
tbpgr_utils-0.0.101 lib/open_classes/file.rb
tbpgr_utils-0.0.100 lib/open_classes/file.rb
tbpgr_utils-0.0.99 lib/open_classes/file.rb
tbpgr_utils-0.0.98 lib/open_classes/file.rb
tbpgr_utils-0.0.97 lib/open_classes/file.rb
tbpgr_utils-0.0.96 lib/open_classes/file.rb
tbpgr_utils-0.0.95 lib/open_classes/file.rb
tbpgr_utils-0.0.94 lib/open_classes/file.rb
tbpgr_utils-0.0.93 lib/open_classes/file.rb
tbpgr_utils-0.0.92 lib/open_classes/file.rb
tbpgr_utils-0.0.91 lib/open_classes/file.rb
tbpgr_utils-0.0.90 lib/open_classes/file.rb
tbpgr_utils-0.0.89 lib/open_classes/file.rb
tbpgr_utils-0.0.88 lib/open_classes/file.rb
tbpgr_utils-0.0.87 lib/open_classes/file.rb
tbpgr_utils-0.0.86 lib/open_classes/file.rb
tbpgr_utils-0.0.85 lib/open_classes/file.rb
tbpgr_utils-0.0.84 lib/open_classes/file.rb