Sha256: 0a5366c29e437296e5b8a48c8fc7a155d3b5254b24d6c063b9acd5a58e32853b

Contents?: true

Size: 1.21 KB

Versions: 10

Compression:

Stored size: 1.21 KB

Contents

module WordCountAnalyzer
  class Punctuation
    # Rubular: http://rubular.com/r/ZVBsZVkiqC
    DOTTED_LINE_REGEX = /…{2,}|\.{5,}/

    # Rubular: http://rubular.com/r/RjZ7qi0uFf
    DASHED_LINE_REGEX = /(?<=\s)-{2,}(\s|$)|\A-{2,}(?=(\s|$))/

    # Rubular: http://rubular.com/r/hNofimZwdh
    UNDERSCORE_REGEX = /(?<=\s)_{2,}(\s|$)|\A_{2,}(?=(\s|$))/

    # Rubular: http://rubular.com/r/FexKxGUuIe
    STRAY_PUNCTUATION_REGEX = /(?<=\s|\A)[[:punct:]](?=(\s|$))|(?<=\s|\A)\|(?=(\s|$))/

    attr_reader :string
    def initialize(string:)
      @string = string
    end

    def dotted_line_ocurrances
      string.scan(DOTTED_LINE_REGEX).size
    end

    def dashed_line_ocurrances
      string.scan(DASHED_LINE_REGEX).size
    end

    def underscore_ocurrances
      string.scan(UNDERSCORE_REGEX).size
    end

    def stray_punctuation_occurences
      string.scan(STRAY_PUNCTUATION_REGEX).size
    end

    def replace_dotted_line
      string.gsub(DOTTED_LINE_REGEX, '')
    end

    def replace_dashed_line
      string.gsub(DASHED_LINE_REGEX, '')
    end

    def replace_underscore
      string.gsub(UNDERSCORE_REGEX, '')
    end

    def replace_stray_punctuation
      string.gsub(STRAY_PUNCTUATION_REGEX, '')
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
word_count_analyzer-1.0.1 lib/word_count_analyzer/punctuation.rb
word_count_analyzer-1.0.0 lib/word_count_analyzer/punctuation.rb
word_count_analyzer-0.0.14 lib/word_count_analyzer/punctuation.rb
word_count_analyzer-0.0.13 lib/word_count_analyzer/punctuation.rb
word_count_analyzer-0.0.12 lib/word_count_analyzer/punctuation.rb
word_count_analyzer-0.0.11 lib/word_count_analyzer/punctuation.rb
word_count_analyzer-0.0.10 lib/word_count_analyzer/punctuation.rb
word_count_analyzer-0.0.9 lib/word_count_analyzer/punctuation.rb
word_count_analyzer-0.0.8 lib/word_count_analyzer/punctuation.rb
word_count_analyzer-0.0.7 lib/word_count_analyzer/punctuation.rb