Class: PragmaticSegmenter::Number

Inherits:
Object
  • Object
show all
Defined in:
lib/pragmatic_segmenter/number.rb

Overview

This class searches for numbers with periods within a string and replaces the periods.

Direct Known Subclasses

Languages::Deutsch::Number

Constant Summary collapse

PeriodBeforeNumberRule =
Rule.new(/\.(?=\d)/, '∯')
NumberAfterPeriodBeforeLetterRule =
Rule.new(/(?<=\d)\.(?=\S)/, '∯')
NewLineNumberPeriodSpaceLetterRule =
Rule.new(/(?<=\r\d)\.(?=(\s\S)|\))/, '∯')
StartLineNumberPeriodRule =
Rule.new(/(?<=^\d)\.(?=(\s\S)|\))/, '∯')
StartLineTwoDigitNumberPeriodRule =
Rule.new(/(?<=^\d\d)\.(?=(\s\S)|\))/, '∯')

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text:) ⇒ Number

Returns a new instance of Number.



23
24
25
# File 'lib/pragmatic_segmenter/number.rb', line 23

def initialize(text:)
  @text = Text.new(text)
end

Instance Attribute Details

#textObject (readonly)

Returns the value of attribute text.



22
23
24
# File 'lib/pragmatic_segmenter/number.rb', line 22

def text
  @text
end

Instance Method Details

#replaceObject



27
28
29
30
31
32
33
# File 'lib/pragmatic_segmenter/number.rb', line 27

def replace
  @text.apply(PeriodBeforeNumberRule).
        apply(NumberAfterPeriodBeforeLetterRule).
        apply(NewLineNumberPeriodSpaceLetterRule).
        apply(StartLineNumberPeriodRule).
        apply(StartLineTwoDigitNumberPeriodRule)
end