tv_renamer 4.0.4 → 4.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7196f271e558831bbc837c987d68fa24393cf70b
4
- data.tar.gz: c61c41067e8f70762485bfe0e2953d4a76ed1c4c
3
+ metadata.gz: 7120c0948030887c39a2512593b7c2e600b6ffa4
4
+ data.tar.gz: 98a5aecbb0af1f492b507471536864d198ea0d4f
5
5
  SHA512:
6
- metadata.gz: ed9c50a4ef17a4196388f25844b20e11e6747fd0f95828fe1c74cc9158bb16bd94b9b3a2ae2aa5df946e5f1bc3c4842765174348eb1891e33606407e246f190c
7
- data.tar.gz: 83a0462dfc98a575582307017a262858151395df957a10b699bfe4c20f12748861230d6bcd54a2aa15e132e411e864fe938e419c368524996275cffb2b5fcf60
6
+ metadata.gz: 80edd9318cf195f3bf2636cf649001157722c70422375c7d51d4defe872d6ea1101547903ca32a2be3edb18b0382148da9df8854431a6a81927c366ea0e109ae
7
+ data.tar.gz: ecb19f95c9ef50793fd1402340470685273774c639a2ad3ea6a25af6c76d766e6c5d40c7addfe4557eb0e6787369f0bfbf1f5295ddc2584232cf3b50115629f9
data/lib/tv_renamer.rb CHANGED
@@ -1,2 +1,2 @@
1
- # require 'tv_renamer/ini'
1
+ require 'tv_renamer/ini'
2
2
  require 'tv_renamer/renamer'
@@ -0,0 +1,157 @@
1
+
2
+ # Ini class - read and write ini files
3
+ # Copyright (C) 2007 Jeena Paradies
4
+ # License: GPL
5
+ # Author: Jeena Paradies (info@jeenaparadies.net)
6
+
7
+ class Ini
8
+
9
+ # :inihash is a hash which holds all ini data
10
+ # :comment is a string which holds the comments on the top of the file
11
+ attr_accessor :inihash, :comment
12
+
13
+ # Creating a new Ini object
14
+ # +path+ is a path to the ini file
15
+ # +load+ if nil restores the data if possible
16
+ # if true restores the data, if not possible raises an error
17
+ # if false does not resotre the data
18
+ def initialize(path, load=nil)
19
+ @path = path
20
+ @inihash = {}
21
+
22
+ if load or ( load.nil? and FileTest.readable_real? @path )
23
+ restore()
24
+ end
25
+ end
26
+
27
+ # Retrive the ini data for the key +key+
28
+ def [](key)
29
+ @inihash[key]
30
+ end
31
+
32
+ # Set the ini data for the key +key+
33
+ def []=(key, value)
34
+ raise TypeError, "String expected" unless key.is_a? String
35
+ raise TypeError, "String or Hash expected" unless value.is_a? String or value.is_a? Hash
36
+
37
+ @inihash[key] = value
38
+ end
39
+
40
+ # Restores the data from file into the object
41
+ def restore()
42
+ @inihash = Ini.read_from_file(@path)
43
+ @comment = Ini.read_comment_from_file(@path)
44
+ end
45
+
46
+ # Store data from the object in the file
47
+ def update()
48
+ Ini.write_to_file(@path, @inihash, @comment)
49
+ end
50
+
51
+ # Reading data from file
52
+ # +path+ is a path to the ini file
53
+ # returns a hash which represents the data from the file
54
+ def Ini.read_from_file(path)
55
+ inihash = {}
56
+ headline = nil
57
+
58
+
59
+ IO.foreach(path) do |line|
60
+
61
+ line = line.strip.split(/#/)[0]
62
+
63
+ # if line is nil, just go to the next one
64
+ next if line.nil?
65
+
66
+ # read it only if the line doesn't begin with a "=" and is long enough
67
+ unless line.length < 2 and line[0,1] == "="
68
+
69
+ # it's a headline if the line begins with a "[" and ends with a "]"
70
+ if line[0,1] == "[" and line[line.length - 1, line.length] == "]"
71
+
72
+ # get rid of the [] and unnecessary spaces
73
+ headline = line[1, line.length - 2 ].strip
74
+ inihash[headline] = {}
75
+ else
76
+
77
+ key, value = line.split(/=/, 2)
78
+
79
+ key = key.strip unless key.nil?
80
+ value = value.strip unless value.nil?
81
+
82
+ unless headline.nil?
83
+ inihash[headline][key] = value
84
+ else
85
+ inihash[key] = value unless key.nil?
86
+ end
87
+ end
88
+ end
89
+ end
90
+
91
+ inihash
92
+ end
93
+
94
+ # Reading comments from file
95
+ # +path+ is a path to the ini file
96
+ # Returns a string with comments from the beginning of the
97
+ # ini file.
98
+ def Ini.read_comment_from_file(path)
99
+ comment = ""
100
+
101
+ IO.foreach(path) do |line|
102
+ line.strip!
103
+ next if line.nil?
104
+
105
+ next unless line[0,1] == "#"
106
+
107
+ comment << "#{line[1, line.length ].strip}\n"
108
+ end
109
+
110
+ comment
111
+ end
112
+
113
+ # Writing a ini hash into a file
114
+ # +path+ is a path to the ini file
115
+ # +inihash+ is a hash representing the ini File. Default is a empty hash.
116
+ # +comment+ is a string with comments which appear on the
117
+ # top of the file. Each line will get a "#" before.
118
+ # Default is no comment.
119
+ def Ini.write_to_file(path, inihash={}, comment=nil)
120
+ raise TypeError, "String expected" unless comment.is_a? String or comment.nil?
121
+
122
+ raise TypeError, "Hash expected" unless inihash.is_a? Hash
123
+ File.open(path, "w") { |file|
124
+
125
+ unless comment.nil?
126
+ comment.each do |line|
127
+ file << "# #{line}"
128
+ end
129
+ end
130
+
131
+ file << Ini.to_s(inihash)
132
+ }
133
+ end
134
+
135
+ # Turn a hash (up to 2 levels deepness) into a ini string
136
+ # +inihash+ is a hash representing the ini File. Default is a empty hash.
137
+ # Returns a string in the ini file format.
138
+ def Ini.to_s(inihash={})
139
+ str = ""
140
+
141
+ inihash.each do |key, value|
142
+ if value.is_a? Hash
143
+ str << "[#{key.to_s}]\n"
144
+
145
+ value.each do |under_key, under_value|
146
+ str << "#{under_key.to_s}=#{under_value.to_s unless under_value.nil?}\n"
147
+ end
148
+
149
+ else
150
+ str << "#{key.to_s}=#{value.to_s unless value2.nil?}\n"
151
+ end
152
+ end
153
+
154
+ str
155
+ end
156
+
157
+ end # end Ini
@@ -1,5 +1,5 @@
1
1
  # renamer.rb
2
- # Version 4.0.0
2
+ # Version 4.0.5
3
3
  # Copyright 2011 Kevin Adler
4
4
  # License: GPL v2
5
5
 
@@ -10,8 +10,6 @@ require 'cgi'
10
10
  require 'fileutils'
11
11
  require 'nokogiri'
12
12
 
13
- require 'ini'
14
-
15
13
  class VideoFile
16
14
  SPLITS = [ ' ', '.' ]
17
15
 
data/test/testrenamer.rb CHANGED
@@ -139,6 +139,11 @@ tests.each do |test, expected|
139
139
  end
140
140
  end
141
141
 
142
+ Dir['*.{avi,wmv,divx,mpg,mpeg,xvid,mp4,mkv}'].each do |file|
143
+ puts "Unexpected file #{file}"
144
+ File::delete(file)
145
+ end
146
+
142
147
  tests.each do |test, expected|
143
148
  newtest = test.dup
144
149
  newtest.gsub!('.', ' ')
@@ -160,6 +165,11 @@ tests.each do |test, expected|
160
165
  end
161
166
  end
162
167
 
168
+ Dir['*.{avi,wmv,divx,mpg,mpeg,xvid,mp4,mkv}'].each do |file|
169
+ puts "Unexpected file #{file}"
170
+ File::delete(file)
171
+ end
172
+
163
173
  if count == 0
164
174
  print "All #{tests.length * 2} tests passed!\n"
165
175
  else
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tv_renamer
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.4
4
+ version: 4.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Adler
@@ -36,6 +36,7 @@ files:
36
36
  - bin/tv_renamer
37
37
  - lib/tv_renamer.rb
38
38
  - lib/tv_renamer/ini.rb
39
+ - lib/tv_renamer/ini1.rb
39
40
  - lib/tv_renamer/renamer.rb
40
41
  - test/testrenamer.rb
41
42
  homepage: https://github.com/adler187/tvrenamer