Sha256: 116a691716be32fd90b35f22456097e8698a2f7342f0a4cf65361f80bb68c119
Contents?: true
Size: 1.3 KB
Versions: 2
Compression:
Stored size: 1.3 KB
Contents
# -*- encoding : utf-8 -*- module Spot class Clean attr_reader :content def initialize(content) @content = content @exclude = YAML.load_file(File.join(File.expand_path(File.dirname(__FILE__)), "exclude.yml")) end def process string = content.strip @exclude.each do |exclude| string = string.gsub(/#{exclude}/i, "") end # Song - A + B + C => Song - A # Song - A abc/def => Song - A abc # Song - A & abc def => Song - A # Song - A "abc def" => Song - A # Song - A [B + C] => Song - A # Song A B.mp3 => Song A B # 10. Song => Song [ /\.[a-z0-9]{2,3}$/, /\[[^\]]*\]/, /".*"/, /'.*'[^s]/, /[&|\/|\+][^\z]*/, /^(\d+.*?[^a-z]+?)/i ].each do |reg| string = string.gsub(reg, '').strip end [ /\(.+?\)/m, /[^a-z0-9]feat(.*?)\s*[^\s]+/i, /[-]+/, /[\s]+/m, /\_/ ].each do |reg| string = string.gsub(reg, ' ').strip end {"ä" => "a", "å" => "a", "ö" => "o"}.each do |from, to| string.gsub!(/#{from}/i, to) end string.gsub(/\A\s|\s\z/, '').gsub(/\s+/, ' ').strip.downcase rescue Encoding::CompatibilityError return string end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
spot-2.0.1 | lib/spot/clean.rb |
spot-2.0.0 | lib/spot/clean.rb |