From 0f708ecde00919a9bdf693443aa929cdeaceebea Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Sun, 17 Oct 2010 03:39:50 -0700 Subject: More abstraction! --- omptagger | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) (limited to 'omptagger') diff --git a/omptagger b/omptagger index 07fb2ed..472562e 100755 --- a/omptagger +++ b/omptagger @@ -301,9 +301,17 @@ class Metadata Output.info(@filename) end + + def save + save_fields if @write + + File.rename(@origname, @filename) unless @filename == @origname + end end class VorbisComment < Metadata + private + def keys Hash['a' => 'ARTIST', 'b' => 'ALBUM', @@ -312,30 +320,24 @@ class VorbisComment < Metadata 't' => 'TITLE'] end - def save - if @write - read.each_key do |field| - metadata.removeField(TagLib::String.new(field)) - end - - @metadata.each do |field, value| - field = TagLib::String.new(field) - - value.each do |value| - metadata.addField(field, TagLib::String.new(value), false) - end - end + def read + metadata.fieldListMap.hash + end - @file.save + def save_fields + read.each_key do |field| + metadata.removeField(TagLib::String.new(field)) end - File.rename(@origname, @filename) unless @filename == @origname - end + @metadata.each do |field, value| + field = TagLib::String.new(field) - private + value.each do |value| + metadata.addField(field, TagLib::String.new(value), false) + end + end - def read - metadata.fieldListMap.hash + @file.save end def valid_field?(field) -- cgit v1.2.3-70-g09d2