Sha256: 9802635169219ccb1acdde45db44b67c3b950abd1e1cfb33500e4c57bb64f1f3
Contents?: true
Size: 1.19 KB
Versions: 1
Compression:
Stored size: 1.19 KB
Contents
require_relative "characteristics/version" require_relative "characteristics/ascii" require_relative "characteristics/binary" require_relative "characteristics/byte" require_relative "characteristics/unicode" class Characteristics def self.type_from_encoding_name(encoding_name) case encoding_name when "US-ASCII" :ascii when "ASCII-8BIT" :binary when /^UTF-/ :unicode when /^ISO-8859-/, /^Windows-125/ :byte else raise ArgumentError, "encoding <#{encoding_name}> not supported" end end def self.create_for_type(char, type) case type when :unicode UnicodeCharacteristics.new(char) when :byte ByteCharacteristics.new(char) when :ascii AsciiCharacteristics.new(char) else BinaryCharacteristics.new(char) end end def self.create(char) create_for_type(char, type_from_encoding_name(char.encoding.name)) end attr_reader :encoding def initialize(char) @is_valid = char.valid_encoding? @encoding = char.encoding @encoding_name = @encoding.name end def valid? @is_valid end def unicode? false end def assigned? end def control? end def blank? end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
characteristics-0.2.0 | lib/characteristics.rb |