Class: Kotoshu::Readers::CompoundPattern
- Inherits:
-
Object
- Object
- Kotoshu::Readers::CompoundPattern
- Defined in:
- lib/kotoshu/readers/aff_data.rb
Overview
Compound pattern for checking compound words.
Instance Attribute Summary collapse
-
#left ⇒ String
Left side pattern.
-
#left_flag ⇒ Object
readonly
Returns the value of attribute left_flag.
-
#left_no_affix ⇒ Object
readonly
Returns the value of attribute left_no_affix.
-
#left_stem ⇒ Object
readonly
Returns the value of attribute left_stem.
-
#replacement ⇒ String?
Optional replacement.
-
#right ⇒ String
Right side pattern.
-
#right_flag ⇒ Object
readonly
Returns the value of attribute right_flag.
-
#right_no_affix ⇒ Object
readonly
Returns the value of attribute right_no_affix.
-
#right_stem ⇒ Object
readonly
Returns the value of attribute right_stem.
Instance Method Summary collapse
-
#initialize(left, right, replacement = nil) ⇒ CompoundPattern
constructor
Create a new compound pattern.
-
#match?(left_part, right_part) ⇒ Boolean
Check if this pattern matches the given left and right parts.
Constructor Details
#initialize(left, right, replacement = nil) ⇒ CompoundPattern
Create a new compound pattern.
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 |
# File 'lib/kotoshu/readers/aff_data.rb', line 307 def initialize(left, right, replacement = nil) @left = left @right = right @replacement = replacement # Parse left side. The separator from partition('/') distinguishes # "no slash" (no flag specified → nil, so the matcher skips the # flag check) from a slash with an empty flag. @left_stem, sep, @left_flag = left.partition('/') @left_flag = nil if sep.empty? @left_stem = '' if @left_stem == '0' @left_no_affix = @left_stem.empty? && left.start_with?('0') # Parse right side @right_stem, sep, @right_flag = right.partition('/') @right_flag = nil if sep.empty? @right_stem = '' if @right_stem == '0' @right_no_affix = @right_stem.empty? && right.start_with?('0') end |
Instance Attribute Details
#left ⇒ String
Left side pattern
298 299 300 |
# File 'lib/kotoshu/readers/aff_data.rb', line 298 def left @left end |
#left_flag ⇒ Object (readonly)
Returns the value of attribute left_flag.
299 300 301 |
# File 'lib/kotoshu/readers/aff_data.rb', line 299 def left_flag @left_flag end |
#left_no_affix ⇒ Object (readonly)
Returns the value of attribute left_no_affix.
299 300 301 |
# File 'lib/kotoshu/readers/aff_data.rb', line 299 def left_no_affix @left_no_affix end |
#left_stem ⇒ Object (readonly)
Returns the value of attribute left_stem.
299 300 301 |
# File 'lib/kotoshu/readers/aff_data.rb', line 299 def left_stem @left_stem end |
#replacement ⇒ String?
Optional replacement
298 299 300 |
# File 'lib/kotoshu/readers/aff_data.rb', line 298 def replacement @replacement end |
#right ⇒ String
Right side pattern
298 299 300 |
# File 'lib/kotoshu/readers/aff_data.rb', line 298 def right @right end |
#right_flag ⇒ Object (readonly)
Returns the value of attribute right_flag.
299 300 301 |
# File 'lib/kotoshu/readers/aff_data.rb', line 299 def right_flag @right_flag end |
#right_no_affix ⇒ Object (readonly)
Returns the value of attribute right_no_affix.
299 300 301 |
# File 'lib/kotoshu/readers/aff_data.rb', line 299 def right_no_affix @right_no_affix end |
#right_stem ⇒ Object (readonly)
Returns the value of attribute right_stem.
299 300 301 |
# File 'lib/kotoshu/readers/aff_data.rb', line 299 def right_stem @right_stem end |
Instance Method Details
#match?(left_part, right_part) ⇒ Boolean
Check if this pattern matches the given left and right parts.
332 333 334 335 336 337 338 339 340 341 |
# File 'lib/kotoshu/readers/aff_data.rb', line 332 def match?(left_part, right_part) return false unless left_part.stem.end_with?(@left_stem) return false unless right_part.stem.start_with?(@right_stem) return false if @left_no_affix && left_part.is_base? return false if @right_no_affix && right_part.is_base? return false if @left_flag && !left_part.flags.include?(@left_flag) return false if @right_flag && !right_part.flags.include?(@right_flag) true end |