Class: Kotoshu::Readers::Affix

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

Overview

Affix data class for Hunspell affix rules.

This class represents a prefix or suffix affix rule.

Examples:

Creating a suffix affix

Affix.new(
  type: :suffix,
  flag: 'H',
  crossproduct: false,
  strip: 'y',
  add: 'ieth',
  condition: 'y',
  flags: Set.new
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, flag:, crossproduct:, strip:, add:, condition:, flags: Set.new) ⇒ Affix

Create a new affix.

Parameters:

  • type (Symbol)

    :prefix or :suffix

  • flag (String)

    Flag character

  • crossproduct (Boolean)

    Whether cross-product

  • strip (String)

    Characters to strip

  • add (String)

    Characters to add

  • condition (String)

    Condition regex

  • flags (Set<String>) (defaults to: Set.new)

    Additional flags



38
39
40
41
42
43
44
45
46
# File 'lib/kotoshu/readers/aff_data.rb', line 38

def initialize(type:, flag:, crossproduct:, strip:, add:, condition:, flags: Set.new)
  @type = type
  @flag = flag
  @crossproduct = crossproduct
  @strip = strip
  @add = add
  @condition = condition
  @flags = flags
end

Instance Attribute Details

#addString

Characters to add to the word

Returns:

  • (String)

    the current value of add



26
27
28
# File 'lib/kotoshu/readers/aff_data.rb', line 26

def add
  @add
end

#conditionString

Condition for applying this rule

Returns:

  • (String)

    the current value of condition



26
27
28
# File 'lib/kotoshu/readers/aff_data.rb', line 26

def condition
  @condition
end

#crossproductBoolean

Whether this is a cross-product rule

Returns:

  • (Boolean)

    the current value of crossproduct



26
27
28
# File 'lib/kotoshu/readers/aff_data.rb', line 26

def crossproduct
  @crossproduct
end

#flagString

The flag character identifying this rule

Returns:

  • (String)

    the current value of flag



26
27
28
# File 'lib/kotoshu/readers/aff_data.rb', line 26

def flag
  @flag
end

#flagsSet<String>

Additional flags

Returns:

  • (Set<String>)

    the current value of flags



26
27
28
# File 'lib/kotoshu/readers/aff_data.rb', line 26

def flags
  @flags
end

#stripString

Characters to strip from the word

Returns:

  • (String)

    the current value of strip



26
27
28
# File 'lib/kotoshu/readers/aff_data.rb', line 26

def strip
  @strip
end

#typeObject (readonly)

Returns the value of attribute type.



27
28
29
# File 'lib/kotoshu/readers/aff_data.rb', line 27

def type
  @type
end

Instance Method Details

#inspectString

Inspect string.

Returns:

  • (String)

    Inspect string



73
74
75
# File 'lib/kotoshu/readers/aff_data.rb', line 73

def inspect
  to_s
end

#prefix?Boolean

Check if this is a prefix.

Returns:

  • (Boolean)

    True if prefix



51
52
53
# File 'lib/kotoshu/readers/aff_data.rb', line 51

def prefix?
  @type == :prefix
end

#suffix?Boolean

Check if this is a suffix.

Returns:

  • (Boolean)

    True if suffix



58
59
60
# File 'lib/kotoshu/readers/aff_data.rb', line 58

def suffix?
  @type == :suffix
end

#to_sString

String representation.

Returns:

  • (String)

    String representation



65
66
67
68
# File 'lib/kotoshu/readers/aff_data.rb', line 65

def to_s
  type_str = prefix? ? 'Prefix' : 'Suffix'
  "#{type_str}(#{@add}: #{@flag}#{@crossproduct ? '×' : ''}/#{@flags.to_a.join(',')}, on #{condition})"
end