Class: Spot::Clean
- Inherits:
-
Object
- Object
- Spot::Clean
- Defined in:
- lib/spot/clean.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
Instance Method Summary collapse
-
#initialize(content) ⇒ Clean
constructor
A new instance of Clean.
- #process ⇒ Object
Constructor Details
#initialize(content) ⇒ Clean
Returns a new instance of Clean.
6 7 8 9 |
# File 'lib/spot/clean.rb', line 6 def initialize(content) @content = content @exclude = YAML.load_file(File.join(File.(File.dirname(__FILE__)), "exclude.yml")) end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
5 6 7 |
# File 'lib/spot/clean.rb', line 5 def content @content end |
Instance Method Details
#process ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/spot/clean.rb', line 11 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+|^)'.*'(\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 |