class WordCountAnalyzer::Slash

Constants

BACKSLASH_REGEX

Rubular: rubular.com/r/tuFWtdMs4G

FORWARD_SLASH_REGEX

Rubular: rubular.com/r/AqvcH29sgg

Attributes

date[R]
processed_string[R]
string[R]
xhtml[R]

Public Class Methods

new(string:, **args) click to toggle source
# File lib/word_count_analyzer/slash.rb, line 10
def initialize(string:, **args)
  @string = string
  @date = args[:date] || nil
  @xhtml = args[:xhtml] || nil
  @hyperlink = args[:hyperlink] || nil
  hyper = WordCountAnalyzer::Hyperlink.new
  if date.eql?('no_special_treatment')
    if xhtml.eql?('keep')
      if hyperlink.eql?('no_special_treatment') || hyperlink.eql?('split_at_period')
        @processed_string = string
      else
        @processed_string = hyper.replace(string)
      end
    else
      if hyperlink.eql?('no_special_treatment') || hyperlink.eql?('split_at_period')
        @processed_string = WordCountAnalyzer::Xhtml.new(string: string).replace
      else
        @processed_string = WordCountAnalyzer::Xhtml.new(string: hyper.replace(string)).replace
      end
    end
  else
    if xhtml.eql?('keep')
      if hyperlink.eql?('no_special_treatment') || hyperlink.eql?('split_at_period')
        @processed_string = WordCountAnalyzer::Date.new.replace(string)
      else
        @processed_string = WordCountAnalyzer::Date.new.replace(hyper.replace(string))
      end
    else
      if hyperlink.eql?('no_special_treatment') || hyperlink.eql?('split_at_period')
        @processed_string = WordCountAnalyzer::Date.new.replace(WordCountAnalyzer::Xhtml.new(string: string).replace)
      else
        @processed_string = WordCountAnalyzer::Date.new.replace(WordCountAnalyzer::Xhtml.new(string: hyper.replace(string)).replace)
      end
    end
  end
end

Public Instance Methods

backslash_occurences() click to toggle source
# File lib/word_count_analyzer/slash.rb, line 76
def backslash_occurences
  processed_string.scan(BACKSLASH_REGEX).size
end
forward_slash_occurences() click to toggle source
# File lib/word_count_analyzer/slash.rb, line 55
def forward_slash_occurences
  processed_string.scan(FORWARD_SLASH_REGEX).size
end
includes_backslash?() click to toggle source
# File lib/word_count_analyzer/slash.rb, line 51
def includes_backslash?
  !(processed_string !~ BACKSLASH_REGEX)
end
includes_forward_slash?() click to toggle source
# File lib/word_count_analyzer/slash.rb, line 47
def includes_forward_slash?
  !(processed_string !~ FORWARD_SLASH_REGEX)
end
replace_backslashes() click to toggle source
# File lib/word_count_analyzer/slash.rb, line 80
def replace_backslashes
  return processed_string if processed_string !~ BACKSLASH_REGEX
  processed_string.gsub!(BACKSLASH_REGEX).each do |match|
    ' word ' * match.split(/\\+/).length
  end
  processed_string
end
replace_forward_slashes() click to toggle source
# File lib/word_count_analyzer/slash.rb, line 59
def replace_forward_slashes
  return processed_string if processed_string !~ FORWARD_SLASH_REGEX
  processed_string.gsub!(FORWARD_SLASH_REGEX).each do |match|
    match.split(/\/+/).join(' ')
  end
  processed_string
end
replace_forward_slashes_except_dates() click to toggle source
# File lib/word_count_analyzer/slash.rb, line 67
def replace_forward_slashes_except_dates
  return processed_string if processed_string !~ FORWARD_SLASH_REGEX
  except_date_string = WordCountAnalyzer::Date.new.replace_number_only_date(processed_string)
  except_date_string.gsub!(FORWARD_SLASH_REGEX).each do |match|
    match.split(/\/+/).join(' ')
  end
  except_date_string
end