Class: Kotoshu::Readers::BreakPattern

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

Overview

Break pattern for word splitting.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pattern) ⇒ BreakPattern

Create a new break pattern.

Parameters:

  • pattern (String)

    The pattern string



88
89
90
91
92
93
94
95
96
97
# File 'lib/kotoshu/readers/aff_data.rb', line 88

def initialize(pattern)
  @pattern = pattern
  # Special chars like #, -, * should be escaped, but ^ and $ should be treated as pattern anchors
  regex_pattern = Regexp.escape(pattern).gsub('\\^', '^').gsub('\\$', '$')
  if regex_pattern.start_with?('^') || regex_pattern.end_with?('$')
    @matcher = Regexp.new("(#{regex_pattern})")
  else
    @matcher = Regexp.new(".(#{regex_pattern}).")
  end
end

Instance Attribute Details

#matcherRegexp

Compiled matcher for the pattern

Returns:

  • (Regexp)

    the current value of matcher



82
83
84
# File 'lib/kotoshu/readers/aff_data.rb', line 82

def matcher
  @matcher
end

#patternString

The break pattern

Returns:

  • (String)

    the current value of pattern



82
83
84
# File 'lib/kotoshu/readers/aff_data.rb', line 82

def pattern
  @pattern
end