Sha256: a12407041250de48cd2939a5d15afddab67a136e7a0b1568d9adef16297521f1

Contents?: true

Size: 491 Bytes

Versions: 1

Compression:

Stored size: 491 Bytes

Contents

# -*- coding: utf-8 -*-
#
# helper.rb
#
  # Convert to US_ASCII encoding if ascii characters only.
  def convert_to_ascii_if_ascii(str)
    return nil if str.nil?
    ruby_18 do
      enc = str.encoding
      begin
        str = str.encode('ASCII')
      rescue
        str.force_encoding(enc)
      end
    end ||
    ruby_19 do
      if !str.nil? && str.ascii_only?
        str = [str].pack('a*')
      end
    end
    str
  end
  private :convert_to_ascii_if_ascii

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
writeexcel-0.4.0 lib/writeexcel/helper.rb