Sha256: 64598da10cfc70aa2342d14398d6590d41e2f1272fcd9dda56ad79ac4af56c17

Contents?: true

Size: 587 Bytes

Versions: 35

Compression:

Stored size: 587 Bytes

Contents

module Krikri::Enrichments
  ##
  # Converts a string to sentence case.
  #
  # @example
  #
  #   string = 'this is a sentence about Moomins. this is another about Snorks.'
  #   Krikri::Enrichments::ConvertToSentenceCase.enrich_value(string)
  #   # => 'This is a sentence about moomins. This is another about snorks.'
  class ConvertToSentenceCase
    include Audumbla::FieldEnrichment

    def enrich_value(value)
      return value unless value.is_a? String
      value.gsub(/([a-z])((?:[^.?!]|\.(?=[a-z]))*)/i) do
        $1.upcase + $2.downcase.rstrip
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
krikri-0.15.2 lib/krikri/enrichments/convert_to_sentence_case.rb
krikri-0.15.1 lib/krikri/enrichments/convert_to_sentence_case.rb
krikri-0.15.0 lib/krikri/enrichments/convert_to_sentence_case.rb
krikri-0.14.0 lib/krikri/enrichments/convert_to_sentence_case.rb
krikri-0.13.2 lib/krikri/enrichments/convert_to_sentence_case.rb
krikri-0.13.1 lib/krikri/enrichments/convert_to_sentence_case.rb
krikri-0.13.0 lib/krikri/enrichments/convert_to_sentence_case.rb
krikri-0.12.4 lib/krikri/enrichments/convert_to_sentence_case.rb
krikri-0.12.3 lib/krikri/enrichments/convert_to_sentence_case.rb
krikri-0.12.1 lib/krikri/enrichments/convert_to_sentence_case.rb
krikri-0.12.0 lib/krikri/enrichments/convert_to_sentence_case.rb
krikri-0.12.0.pre.rc.1 lib/krikri/enrichments/convert_to_sentence_case.rb
krikri-0.11.2 lib/krikri/enrichments/convert_to_sentence_case.rb
krikri-0.11.1 lib/krikri/enrichments/convert_to_sentence_case.rb
krikri-0.11.0 lib/krikri/enrichments/convert_to_sentence_case.rb
krikri-0.10.1 lib/krikri/enrichments/convert_to_sentence_case.rb
krikri-0.10.0 lib/krikri/enrichments/convert_to_sentence_case.rb
krikri-0.9.0 lib/krikri/enrichments/convert_to_sentence_case.rb
krikri-0.8.9 lib/krikri/enrichments/convert_to_sentence_case.rb
krikri-0.8.8 lib/krikri/enrichments/convert_to_sentence_case.rb