Sha256: 71ebf654db102aa0e3fe08952ae35b867c953384491042bb85bfdf3012cb231d

Contents?: true

Size: 1.21 KB

Versions: 6

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)[[:punct:]](?=(\s|$))|(?<=\s)\|(?=(\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

6 entries across 6 versions & 1 rubygems

Version Path
word_count_analyzer-0.0.6 lib/word_count_analyzer/punctuation.rb
word_count_analyzer-0.0.5 lib/word_count_analyzer/punctuation.rb
word_count_analyzer-0.0.4 lib/word_count_analyzer/punctuation.rb
word_count_analyzer-0.0.3 lib/word_count_analyzer/punctuation.rb
word_count_analyzer-0.0.2 lib/word_count_analyzer/punctuation.rb
word_count_analyzer-0.0.1 lib/word_count_analyzer/punctuation.rb