Module: TWFilter::Han
- Defined in:
- lib/twfilter/han.rb,
sig/twfilter.rbs
Constant Summary collapse
- CHAR =
/\p{Han}/- RUN =
/\p{Han}+/- BMP =
CJK Unified Ideographs and Extension A — the planes a Taiwanese font is expected to render. \pTWFilter::Han is wider; .basic? distinguishes the two.
(0x4E00..0x9FFF).freeze
- EXTENSION_A =
(0x3400..0x4DBF).freeze
Class Method Summary collapse
- .basic?(char) ⇒ Boolean
- .char?(char) ⇒ Boolean
- .count(text) ⇒ ::Integer
- .ratio(text) ⇒ ::Float
- .runs(text) ⇒ ::Array[::String]
Class Method Details
.basic?(char) ⇒ Boolean
25 26 27 28 |
# File 'lib/twfilter/han.rb', line 25 def basic?(char) code = char.ord BMP.cover?(code) || EXTENSION_A.cover?(code) end |
.count(text) ⇒ ::Integer
16 |
# File 'lib/twfilter/han.rb', line 16 def count(text) = text.each_char.count { |char| char.match?(CHAR) } |
.ratio(text) ⇒ ::Float
20 21 22 23 |
# File 'lib/twfilter/han.rb', line 20 def ratio(text) length = text.length length.zero? ? 0.0 : count(text).fdiv(length) end |
.runs(text) ⇒ ::Array[::String]
18 |
# File 'lib/twfilter/han.rb', line 18 def runs(text) = text.scan(RUN) |