Class: Unihan2

Inherits:
Object
  • Object
show all
Defined in:
lib/unihan2.rb

Constant Summary collapse

DATA_DIR =
File.join(File.dirname(__FILE__), '../data')

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeUnihan2

Returns a new instance of Unihan2.



6
7
8
9
# File 'lib/unihan2.rb', line 6

def initialize
  read_strokes
  read_version
end

Class Method Details

.chars_ver(xml_file_in, csv_file_out) ⇒ Object

將 Unicode XML 轉為 CSV, 內含 code range 的 unicode 版本

Parameters:

  • xml_file_in (String)

    input unicode xml file path, ex: “ucd.all.flat.xml”

  • csv_file_out (String)

    csv file path for output



14
15
16
# File 'lib/unihan2.rb', line 14

def self.chars_ver(xml_file_in, csv_file_out)
  UnicodeCharsVer.new.convert(xml_file_in, csv_file_out)
end

Instance Method Details

#strokes(char) ⇒ Integer

return total strokes of the character char

Parameters:

  • char (String)

    the character

Returns:

  • (Integer)

    the total strokes



21
22
23
# File 'lib/unihan2.rb', line 21

def strokes(char)
  @strokes[char]
end

#ver(code) ⇒ Float

return unicode version of specific character

Parameters:

  • code (String)

    character or codepoint

Returns:

  • (Float)

    unicode version



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/unihan2.rb', line 28

def ver(code)
  return nil if code.nil?

  if code.is_a? Integer
    i = code
  elsif code.size == 1
    i = code.codepoints.first
  else
    i = code.hex
  end

  ver_bsearch(i, 0, @vers.size-1)
end