Sha256: 96728a78c3b8ce0a78ff1e57d77794547ce8ad65fc5bebd037d4b3258206dc92

Contents?: true

Size: 1.23 KB

Versions: 1

Compression:

Stored size: 1.23 KB

Contents

require 'yaml'

module Serienrenamer

    # this class holds a storage for episode information (seriesname)
    # in form of a yaml file which can be used from other tools
    class InformationStore

        attr_reader :episode_hash

        # this method will load an exisiting yaml file and tries to rebuild
        # the used hash with episode data
        def initialize(yaml_path)
            @yaml_path = yaml_path
            @episode_hash = {}

            if File.file?(yaml_path)
                @episode_hash = YAML.load(File.new(yaml_path, "rb").read)
            end
        end

        # this method will store the information of the supplied episode
        # instance to the file
        def store(episode)
            raise ArgumentError, "Episode instance needed" unless
                episode.is_a? Serienrenamer::Episode

            unless @episode_hash[episode.md5sum]
                @episode_hash[episode.md5sum] = episode.series
            end
        end

        # this method will write the current hash of episodes to the
        # yaml file
        def write()
            storage_file = File.new(@yaml_path, "w")
            storage_file.write(@episode_hash.to_yaml)
            storage_file.close
        end
    end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
serienrenamer-0.0.4 lib/serienrenamer/information_store.rb