Module: TWFilter::Checks::Erhua
- Defined in:
- lib/twfilter/checks/erhua.rb,
sig/twfilter.rbs
Constant Summary collapse
- NAME =
:erhua- MARK =
兒 is a root morpheme inside a headed or tailed window, and an erhua suffix elsewhere.
"兒"
Class Method Summary collapse
- .call(subject) ⇒ ::Array[Finding]
- .headed ⇒ ::Set[::String]
- .offender(text) ⇒ ::String?
- .tailed ⇒ ::Set[::String]
Class Method Details
.call(subject) ⇒ ::Array[Finding]
11 12 13 14 15 16 |
# File 'lib/twfilter/checks/erhua.rb', line 11 def call(subject) offender = offender(subject.text) return [] if offender.nil? [Finding.new(check: NAME, code: :erhua, detail: offender)] end |
.headed ⇒ ::Set[::String]
34 |
# File 'lib/twfilter/checks/erhua.rb', line 34 def headed = Tables.set("erhua_headed.txt") |
.offender(text) ⇒ ::String?
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/twfilter/checks/erhua.rb', line 18 def offender(text) return nil if text == MARK position = 0 while (position = text.index(MARK, position)) after = text[position, 2] before = position.positive? ? text[position - 1, 2] : nil return before || MARK unless headed.include?(after) || tailed.include?(before) position += 1 end nil end |