Class: Serienrenamer::InformationStore
- Inherits:
-
Object
- Object
- Serienrenamer::InformationStore
- Defined in:
- lib/serienrenamer/information_store.rb
Overview
this class holds a storage for episode information (seriesname) in form of a yaml file which can be used from other tools
Instance Attribute Summary collapse
-
#byte_count ⇒ Object
readonly
Returns the value of attribute byte_count.
-
#episode_hash ⇒ Object
readonly
Returns the value of attribute episode_hash.
Instance Method Summary collapse
-
#initialize(yaml_path, byte_count = 2048) ⇒ InformationStore
constructor
this method will load an exisiting yaml file and tries to rebuild the used hash with episode data.
-
#store(episode) ⇒ Object
this method will store the information of the supplied episode instance to the file.
-
#write ⇒ Object
this method will write the current hash of episodes to the yaml file.
Constructor Details
#initialize(yaml_path, byte_count = 2048) ⇒ InformationStore
this method will load an exisiting yaml file and tries to rebuild the used hash with episode data
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/serienrenamer/information_store.rb', line 13 def initialize(yaml_path, byte_count=2048) @yaml_path = yaml_path @byte_count = byte_count.to_i @episode_hash = {} if File.file?(yaml_path) serialized = YAML.load(File.new(yaml_path, "rb").read) if serialized.is_a?(Hash) @episode_hash = serialized end end end |
Instance Attribute Details
#byte_count ⇒ Object (readonly)
Returns the value of attribute byte_count.
9 10 11 |
# File 'lib/serienrenamer/information_store.rb', line 9 def byte_count @byte_count end |
#episode_hash ⇒ Object (readonly)
Returns the value of attribute episode_hash.
9 10 11 |
# File 'lib/serienrenamer/information_store.rb', line 9 def episode_hash @episode_hash end |
Instance Method Details
#store(episode) ⇒ Object
this method will store the information of the supplied episode instance to the file
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/serienrenamer/information_store.rb', line 28 def store(episode) raise ArgumentError, "Episode instance needed" unless episode.is_a? Serienrenamer::Episode md5sum = episode.md5sum(@byte_count) unless @episode_hash[md5sum] @episode_hash[md5sum] = episode.series end end |
#write ⇒ Object
this method will write the current hash of episodes to the yaml file
41 42 43 44 45 |
# File 'lib/serienrenamer/information_store.rb', line 41 def write() storage_file = File.new(@yaml_path, "w") storage_file.write(@episode_hash.to_yaml) storage_file.close end |