Class: Kotoshu::Readers::BreakPattern
- Inherits:
-
Object
- Object
- Kotoshu::Readers::BreakPattern
- Defined in:
- lib/kotoshu/readers/aff_data.rb
Overview
Break pattern for word splitting.
Instance Attribute Summary collapse
-
#matcher ⇒ Regexp
Compiled matcher for the pattern.
-
#pattern ⇒ String
The break pattern.
Instance Method Summary collapse
-
#initialize(pattern) ⇒ BreakPattern
constructor
Create a new break pattern.
Constructor Details
#initialize(pattern) ⇒ BreakPattern
Create a new break pattern.
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
#matcher ⇒ Regexp
Compiled matcher for the pattern
82 83 84 |
# File 'lib/kotoshu/readers/aff_data.rb', line 82 def matcher @matcher end |
#pattern ⇒ String
The break pattern
82 83 84 |
# File 'lib/kotoshu/readers/aff_data.rb', line 82 def pattern @pattern end |