Class: Tagomatic::TagCleaner

Inherits:
Object
  • Object
show all
Defined in:
lib/tagomatic/tag_cleaner.rb

Instance Method Summary collapse

Instance Method Details

#process(tags_hash) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/tagomatic/tag_cleaner.rb', line 5

def process(tags_hash)
  artist = tags_hash['a']
  artist = Regexp.compile("[ -]*#{Regexp.escape(artist)}[ -]*", Regexp::IGNORECASE) if artist

  album = tags_hash['b']
  album = album.sub(artist, '') if artist and album
  tags_hash['b'] = album unless album.nil? or album.empty?

  album = Regexp.compile("[ -]*#{Regexp.escape(album)}[ -]*", Regexp::IGNORECASE) if album

  title = tags_hash['t']
  title = title.sub(artist, '') if artist and title
  title = title.sub(album, '') if album and title
  tags_hash['t'] = title unless title.nil? or title.empty?

  tags_hash
end