Class: DataMaker::Validators::ChineseCharacters

Inherits:
Object
  • Object
show all
Defined in:
lib/data_maker/validators/chinese_characters.rb

Constant Summary collapse

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" } ]

Instance Method Summary collapse

Constructor Details

#initialize(characters) ⇒ ChineseCharacters

Returns a new instance of ChineseCharacters.



12
13
14
# File 'lib/data_maker/validators/chinese_characters.rb', line 12

def initialize(characters)
  @characters = characters
end

Instance Method Details

#valid?Boolean

Returns:

  • (Boolean)


16
17
18
19
20
21
22
# File 'lib/data_maker/validators/chinese_characters.rb', line 16

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