Class: Mp3FileName
- Inherits:
-
Object
- Object
- Mp3FileName
- Defined in:
- lib/mp3filename.rb
Constant Summary collapse
- VERSION =
"1.0.3"
Instance Method Summary collapse
- #change ⇒ Object
- #convert_file_name(mp3, file) ⇒ Object
-
#initialize(path) ⇒ Mp3FileName
constructor
A new instance of Mp3FileName.
Constructor Details
#initialize(path) ⇒ Mp3FileName
Returns a new instance of Mp3FileName.
8 9 10 |
# File 'lib/mp3filename.rb', line 8 def initialize(path) @path = path end |
Instance Method Details
#change ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/mp3filename.rb', line 12 def change Dir["#{@path}/*.mp3"].each do |old_file_name| Mp3Info.open(old_file_name) do |mp3| new_file_name = convert_file_name(mp3, old_file_name) begin FileUtils.mv("#{old_file_name}", "#{@path}/#{new_file_name}.mp3") puts "'#{old_file_name.split('/')[-1]}' changed to '#{new_file_name}.mp3'" rescue next end end end end |
#convert_file_name(mp3, file) ⇒ Object
26 27 28 29 |
# File 'lib/mp3filename.rb', line 26 def convert_file_name(mp3, file) file_name = mp3.tag.title ? "#{mp3.tag.title}" : file.split('.mp3')[0] file_name.gsub(/[\d_\-\[\]]/,'').gsub(/(\w+\.)+\w+/,'').strip end |