Sha256: 985c98d1f29fa90bc3f8b75481c0181217546b078235e5cf3ba0cf93808af002

Contents?: true

Size: 1.18 KB

Versions: 13

Compression:

Stored size: 1.18 KB

Contents

module DataMaker
  module Validators
    class ChineseCharacters

      CJK_CHARACTER_RANGES = [ { min: "4E00",  max: "9FFF",  comment: "Common" },
                               { min: "3400",  max: "4DFF",  comment: "Rare" },
                               { min: "20000", max: "2A6DF", comment: "Rare, historic" },
                               { min: "F900",  max: "FAFF",  comment: "Duplicates, unifiable variants" },
                               { min: "2F800", max: "2FA1F", comment: "unifiable variants" },
                               { min: "AC00",  max: "D7AF",  comment: "Hangul syllables" } ]

      def initialize(characters)
        @characters = characters
      end

      def valid?
        valid_characters = true
        @characters.each_char do |character|
          hex_chinese = "%04x" % character[0].ord
          valid_characters = true unless within_cjk_range(hex_chinese)
        end
      end

      private

      def within_cjk_range(hex_string)
        val = hex_string.hex
        CJK_CHARACTER_RANGES.each do |valid_range|
          return true if val >= valid_range[:min].hex && val <= valid_range[:max].hex
        end

        return false
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
data_maker-2.5.5 lib/data_maker/validators/chinese_characters.rb
data_maker-2.5.4 lib/data_maker/validators/chinese_characters.rb
data_maker-2.5.3 lib/data_maker/validators/chinese_characters.rb
data_maker-2.5.2 lib/data_maker/validators/chinese_characters.rb
data_maker-2.4.2 lib/data_maker/validators/chinese_characters.rb
data_maker-2.4.1 lib/data_maker/validators/chinese_characters.rb
data_maker-2.3.5 lib/data_maker/validators/chinese_characters.rb
data_maker-2.3.4 lib/data_maker/validators/chinese_characters.rb
data_maker-2.3.3 lib/data_maker/validators/chinese_characters.rb
data_maker-2.2.3 lib/data_maker/validators/chinese_characters.rb
data_maker-2.1.3 lib/data_maker/validators/chinese_characters.rb
data_maker-2.1.2 lib/data_maker/validators/chinese_characters.rb
data_maker-2.1.1 lib/data_maker/validators/chinese_characters.rb