Class: Kotoshu::Readers::PhonetTable::Rule

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

Overview

Rule class for phonetic transformations.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#endBoolean

Match at end

Returns:

  • (Boolean)

    the current value of end



366
367
368
# File 'lib/kotoshu/readers/aff_data.rb', line 366

def end
  @end
end

#followupBoolean

Follow-up rule

Returns:

  • (Boolean)

    the current value of followup



366
367
368
# File 'lib/kotoshu/readers/aff_data.rb', line 366

def followup
  @followup
end

#priorityInteger

Rule priority

Returns:

  • (Integer)

    the current value of priority



366
367
368
# File 'lib/kotoshu/readers/aff_data.rb', line 366

def priority
  @priority
end

#replacementString

Replacement string

Returns:

  • (String)

    the current value of replacement



366
367
368
# File 'lib/kotoshu/readers/aff_data.rb', line 366

def replacement
  @replacement
end

#searchRegexp

Search pattern

Returns:

  • (Regexp)

    the current value of search



366
367
368
# File 'lib/kotoshu/readers/aff_data.rb', line 366

def search
  @search
end

#startBoolean

Match at start

Returns:

  • (Boolean)

    the current value of start



366
367
368
# File 'lib/kotoshu/readers/aff_data.rb', line 366

def start
  @start
end

Instance Method Details

#match?(word, pos) ⇒ Boolean

Check if rule matches at position.

Parameters:

  • word (String)

    Word to check

  • pos (Integer)

    Position in word

Returns:

  • (Boolean)

    True if matches



395
396
397
# File 'lib/kotoshu/readers/aff_data.rb', line 395

def match?(word, pos)
  !match_length(word, pos).nil?
end

#match_length(word, pos) ⇒ Integer?

Length of the match if this rule fires at pos in word, or nil if the rule doesn't match. The metaphone walker uses the length to advance its position past the consumed input.

Parameters:

  • word (String)

    Word to match against

  • pos (Integer)

    Position in word

Returns:

  • (Integer, nil)

    Length of matched substring, or nil



374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
# File 'lib/kotoshu/readers/aff_data.rb', line 374

def match_length(word, pos)
  return nil if start && pos.positive?

  match_data = if self[:end]
                 # Anchor at end of word: strip the prefix so
                 # the regex can match without considering the
                 # preceding characters.
                 search.match(word[pos..])
               else
                 search.match(word, pos)
               end
  return nil unless match_data

  match_data.to_s.length
end