Sha256: 03d2913c48a3208a91314505527c69ce741fc3ef87e87c62ef0ce3580cd6471c
Contents?: true
Size: 1.01 KB
Versions: 2
Compression:
Stored size: 1.01 KB
Contents
# frozen_string_literal: true require_relative "blacklistergem/version" require 'yaml' # require the yaml file to be read in module Blacklistergem class Error < StandardError; end class Base class << self # assign class to itself so self does not need to be used for every method def blacklist @blacklist ||= YAML.load_file('lib/blacklist.yml') # load the yml file containing the blacklisted words and assign it to blacklist variable end def sanitize(input = "sassy") # method to take in user input to check for profanity word = input.downcase # set user input to downcase case to consistency blacklist.each do |key, value| # for each word in the blacklist assign it a key(profane word), and a value(areplace profane word with asterisk) word.gsub!(/\b#{key}\b/, value) # for each word the user has inputed replace the old word(key) with the new word(value) end word # return the word whether it contains profanity or not end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
blacklistergem-0.1.10 | lib/blacklistergem.rb |
blacklistergem-0.1.8 | lib/blacklistergem.rb |