Sha256: ba8a4ad11152ffe16bb31664af3e30e9a87a1c0387cc50537a6c127ac76e8671

Contents?: true

Size: 950 Bytes

Versions: 3

Compression:

Stored size: 950 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)
      @updates[tag] = value
    end

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

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

  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tagomatic-0.1.0 lib/tagomatic/info_updater.rb
tagomatic-0.0.3 lib/tagomatic/info_updater.rb
tagomatic-0.0.2 lib/tagomatic/info_updater.rb