Class: Kotoshu::Readers::Ignore

Inherits:
Object
  • Object
show all
Defined in:
lib/kotoshu/readers/aff_data.rb

Overview

Ignore characters for lookup/suggest.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(chars) ⇒ Ignore

Create a new ignore set.

Parameters:

  • chars (String)

    Characters to ignore



110
111
112
113
114
# File 'lib/kotoshu/readers/aff_data.rb', line 110

def initialize(chars)
  @chars = chars
  # Create translation table that removes these characters
  @translation_table = chars.each_char.each_with_index.to_h
end

Instance Attribute Details

#charsString

Characters to ignore

Returns:

  • (String)

    the current value of chars



104
105
106
# File 'lib/kotoshu/readers/aff_data.rb', line 104

def chars
  @chars
end

#translation_tableHash

Translation table for removal

Returns:

  • (Hash)

    the current value of translation_table



104
105
106
# File 'lib/kotoshu/readers/aff_data.rb', line 104

def translation_table
  @translation_table
end

Instance Method Details

#remove(str) ⇒ String

Remove ignored characters from string.

Parameters:

  • str (String)

    Input string

Returns:

  • (String)

    String with ignored chars removed



120
121
122
# File 'lib/kotoshu/readers/aff_data.rb', line 120

def remove(str)
  str.chars.reject { |c| @translation_table.key?(c) }.join
end