Class: NHKore::Cleaner

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

Direct Known Subclasses

BasicCleaner

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.clean_any(obj, cleaners) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/nhkore/cleaner.rb', line 29

def self.clean_any(obj,cleaners)
  return nil if obj.nil?

  cleaners = Array(cleaners)

  return obj if cleaners.empty?

  if obj.is_a?(Word)
    obj = Word.new(
      kana: clean_any(obj.kana,cleaners),
      kanji: clean_any(obj.kanji,cleaners),
      word: obj
    )
  else # String
    cleaners.each do |cleaner|
      obj = cleaner.clean(obj)
    end
  end

  return obj
end

Instance Method Details

#begin_clean(str) ⇒ Object



18
19
20
# File 'lib/nhkore/cleaner.rb', line 18

def begin_clean(str)
  return str
end

#clean(str) ⇒ Object



22
23
24
25
26
27
# File 'lib/nhkore/cleaner.rb', line 22

def clean(str)
  str = begin_clean(str)
  str = end_clean(str)

  return str
end