Skip to content

Instantly share code, notes, and snippets.

@spikegrobstein
Created June 19, 2013 10:36
Show Gist options
  • Save spikegrobstein/5813363 to your computer and use it in GitHub Desktop.
Save spikegrobstein/5813363 to your computer and use it in GitHub Desktop.
example of my concept implementation degrawlixer for teamonetickets. basic
The Fucking Champs
Fucking Champs
The Fucking Am
Starfucker
Butthole Surfers
Turbonegro
Goblin Cock
Alabama Thunderpussy
God Below
God Forbid
require 'bundler/setup'
require 'pry'
class Degrawlixer
attr_reader :db
def initialize(db_path)
load_db(db_path)
end
def load_db(db_path)
@db = []
File.open(db_path, 'r').each do |line|
@db << line.chomp
end
end
def translate(name)
return name unless grawlixed? name
r = convert_to_regex(name)
return name if r.nil?
db.each do |correct_name|
next unless correct_name.length == name.length
return correct_name if correct_name.match(r)
end
return name
end
def grawlixed?(name)
!!name.match(/[*\-]/)
end
# convert "The F***ing Champs" -> /^The F...ing Champs$/
def convert_to_regex(name)
return nil unless gawlixed?(name)
return nil if name.gsub(/^[*\-]*$/, '')
o = name.gsub(/([*\-]*)/) do |m|
'.' * m.length
end
Regexp.new "^#{o}$", 'i'
end
end
source 'https://rubygems.org'
gem 'rspec'
gem 'pry'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment