Sha256: a67d9b023757db8dafebf82aee21571000deadfeaa50e53afa573090400c68a0

Contents?: true

Size: 996 Bytes

Versions: 9

Compression:

Stored size: 996 Bytes

Contents

module Tagomatic

  class InfoUpdater

    def initialize(mp3info)
      @info = mp3info
      @updates = {}
    end

    def apply
      @updates.each { |tag, value| write(tag, value) }
    end

    def dirty?
      @updates.each do |tag, value|
        current_value = read(tag).to_s
        return true if current_value != value.to_s
      end
      false
    end

    def album=(value)
      update :album, value
    end

    def artist=(value)
      update :artist, value
    end

    def genre_s=(value)
      update :genre_s, value
    end

    def title=(value)
      update :title, value
    end

    def tracknum=(value)
      update :tracknum, value
    end

    def year=(value)
      update :year, value
    end

    protected

    def update(tag, value)
      value.strip if value.respond_to?(:strip)
      @updates[tag] = value
    end

    def read(tag)
      @info.tag.send(tag)
    end

    def write(tag, value)
      @info.tag.send "#{tag}=".to_sym, value
    end

  end

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
tagomatic-0.1.9 lib/tagomatic/info_updater.rb
tagomatic-0.1.8 lib/tagomatic/info_updater.rb
tagomatic-0.1.7 lib/tagomatic/info_updater.rb
tagomatic-0.1.6 lib/tagomatic/info_updater.rb
tagomatic-0.1.5 lib/tagomatic/info_updater.rb
tagomatic-0.1.4 lib/tagomatic/info_updater.rb
tagomatic-0.1.3 lib/tagomatic/info_updater.rb
tagomatic-0.1.2 lib/tagomatic/info_updater.rb
tagomatic-0.1.1 lib/tagomatic/info_updater.rb