Sha256: 06198aec417066af9e4b04254efda9ef565791dd1076c0079366c7cd671c7bba

Contents?: true

Size: 571 Bytes

Versions: 28

Compression:

Stored size: 571 Bytes

Contents

module Krikri::Enrichments
  ##
  # Strip ending punctuation
  #
  #   StripEndingPunctuation.new
  #     .enrich_value("moomin!...!;,.",)
  #   # => "moomin"
  #
  # Leaves quotation marks and closing parentheses & brackets. Also
  # leaves periods when they follow a one or two letter abbreviation.
  class StripEndingPunctuation
    include Audumbla::FieldEnrichment

    def enrich_value(value)
      return value unless value.is_a? String
      value.gsub!(/[^\p{Alnum}\'\"\)\]\}]*$/, '') unless
        value.match /\s+[a-z]{1,2}\.$/i
      value
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
krikri-0.8.7 lib/krikri/enrichments/strip_ending_punctuation.rb
krikri-0.8.6 lib/krikri/enrichments/strip_ending_punctuation.rb
krikri-0.8.5 lib/krikri/enrichments/strip_ending_punctuation.rb
krikri-0.8.4 lib/krikri/enrichments/strip_ending_punctuation.rb
krikri-0.8.3 lib/krikri/enrichments/strip_ending_punctuation.rb
krikri-0.8.2 lib/krikri/enrichments/strip_ending_punctuation.rb
krikri-0.8.1 lib/krikri/enrichments/strip_ending_punctuation.rb
krikri-0.8.0 lib/krikri/enrichments/strip_ending_punctuation.rb