Sha256: c8c93e7319937704144237d04eb86a8c57d3937eb86e11da431e3d66253c7c13

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

require_relative "types/constants"

module Unicode
  module Types
    def self.types(string)
      res = []
      string.each_char{ |char|
        type_name = type(char)
        res << type_name unless res.include?(type_name)
      }   
      res.sort
    end 
    class << self; alias of types; end 

    def self.type(char)
      require_relative 'types/index' unless defined? ::Unicode::Types::INDEX
      codepoint_depth_offset = char.ord or
          raise(ArgumentError, "Unicode::Types.type must be given a valid char")
      index_or_value = INDEX[:TYPES]
      [0x10000, 0x1000, 0x100, 0x10].each{ |depth|
        index_or_value         = index_or_value[codepoint_depth_offset / depth]
        codepoint_depth_offset = codepoint_depth_offset % depth
        unless index_or_value.is_a? Array
          return INDEX[:TYPE_NAMES][index_or_value.to_i]
        end
      }
      INDEX[:TYPE_NAMES][index_or_value[codepoint_depth_offset].to_i]
    end 

    def self.names
      require_relative 'types/index' unless defined? ::Unicode::Types::INDEX
      INDEX[:TYPE_NAMES].dup
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
unicode-types-1.1.1 lib/unicode/types.rb