Module: TWFilter::Checks::Shape

Defined in:
lib/twfilter/checks/shape.rb,
sig/twfilter.rbs

Constant Summary collapse

NAME =

Returns:

  • (::Symbol)
:shape

Class Method Summary collapse

Class Method Details

.call(subject) ⇒ ::Array[Finding]

Parameters:

Returns:



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/twfilter/checks/shape.rb', line 10

def call(subject)
  return [finding(:empty)] if subject.empty?

  findings = []
  findings << finding(:no_han) if subject.han.zero?

  range = subject.policy.han_range
  unless range.cover?(subject.han)
    code = subject.han < range.first ? :too_short : :too_long
    findings << finding(code, subject.han.to_s)
  end

  if subject.ratio < subject.policy.min_han_ratio
    findings << finding(:low_han_ratio, format("%.2f", subject.ratio))
  end

  offenders = Punctuation.offenders(subject.text, punctuation: subject.policy.punctuation)
  findings << finding(:junk_characters, offenders.first(DETAIL_SAMPLE).join) if offenders.any?

  unless subject.policy.allow_latin
    latin = subject.text.scan(/[A-Za-z]+/).uniq
    findings << finding(:latin, latin.first(DETAIL_SAMPLE).join(" ")) if latin.any?
  end

  findings
end

.finding(code, detail = nil) ⇒ Object



37
# File 'lib/twfilter/checks/shape.rb', line 37

def finding(code, detail = nil) = Finding.new(check: NAME, code: code, detail: detail)