Sha256: 116ab79049eef0ab3308a025bc77aae9c7e34f395556d1e6cdd4dd209b8991ce
Contents?: true
Size: 1021 Bytes
Versions: 1
Compression:
Stored size: 1021 Bytes
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) # 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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
blacklistergem-0.2.0 | lib/blacklistergem.rb |