Class: Kotoshu::Readers::PhonetTable::Rule
- Inherits:
-
Struct
- Object
- Struct
- Kotoshu::Readers::PhonetTable::Rule
- Defined in:
- lib/kotoshu/readers/aff_data.rb
Overview
Rule class for phonetic transformations.
Instance Attribute Summary collapse
-
#end ⇒ Boolean
Match at end.
-
#followup ⇒ Boolean
Follow-up rule.
-
#priority ⇒ Integer
Rule priority.
-
#replacement ⇒ String
Replacement string.
-
#search ⇒ Regexp
Search pattern.
-
#start ⇒ Boolean
Match at start.
Instance Method Summary collapse
-
#match?(word, pos) ⇒ Boolean
Check if rule matches at position.
-
#match_length(word, pos) ⇒ Integer?
Length of the match if this rule fires at
posinword, or nil if the rule doesn't match.
Instance Attribute Details
#end ⇒ Boolean
Match at end
366 367 368 |
# File 'lib/kotoshu/readers/aff_data.rb', line 366 def end @end end |
#followup ⇒ Boolean
Follow-up rule
366 367 368 |
# File 'lib/kotoshu/readers/aff_data.rb', line 366 def followup @followup end |
#priority ⇒ Integer
Rule priority
366 367 368 |
# File 'lib/kotoshu/readers/aff_data.rb', line 366 def priority @priority end |
#replacement ⇒ String
Replacement string
366 367 368 |
# File 'lib/kotoshu/readers/aff_data.rb', line 366 def replacement @replacement end |
#search ⇒ Regexp
Search pattern
366 367 368 |
# File 'lib/kotoshu/readers/aff_data.rb', line 366 def search @search end |
#start ⇒ Boolean
Match at 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.
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.
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 |