Sha256: 9b439dd5950ecc6e42b3ba24e83c2afed9a767658773577b41166252e97032ad

Contents?: true

Size: 917 Bytes

Versions: 1

Compression:

Stored size: 917 Bytes

Contents

# encoding: utf-8
require 'open_classes/numeric/is_ascii'
require 'open_classes/string/justify_table'
require 'open_classes/string/ascii1_other2_size'

# String
class String
  # get ascii_unicode_table
  #
  # === Example
  #
  # input
  #   'aあb'
  #
  # result
  #
  #   |char|ASCII|ascii2 |Unicode|
  #   | a  | 97  |1100001|  --   |
  #   | あ | --  |  --   |0x3042 |
  #   | b  | 98  |1100010|  --   |
  #
  def ascii_unicode_table
    ret = ['|char|ASCII|ascii2|Unicode|']
    chars.each do |c|
      each_ret = []
      each_ret << "|#{c}"
      if c.ord.ascii?
        each_ret << c.ord
        each_ret << c.ord.to_s(2)
        each_ret << '--'
      else
        each_ret << '--'
        each_ret << '--'
        each_ret << "0x#{c.ord.to_s(16)}"
      end
      ret << each_ret.join('|') + '|'
    end
    (ret.join("\n") + "\n").justify_table(:center)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tbpgr_utils-0.0.151 lib/open_classes/string/ascii_unicode_table.rb