sindex 0.1.4 → 0.1.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.
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Sindex [![Build Status](https://secure.travis-ci.org/pboehm/sindex.png)](http://travis-ci.org/pboehm/sindex)
2
2
 
3
3
  Sindex is a tool and library that manages an index file, which contains the tv
4
- series and episodes you have been watched. This index can be used by other
4
+ series and episodes you have watched. This index can be used by other
5
5
  tools like `sjunkieex` to determine new episodes that you are interested in.
6
6
  [Here](https://github.com/pboehm/sindex/blob/master/test/seriesindex_example.xml)
7
7
  is an example, how an index looks like and what features are supported.
@@ -18,6 +18,9 @@ module Sindex
18
18
  @series_data = {}
19
19
  @series_aliases = {}
20
20
 
21
+ @dtd_path = File.expand_path(
22
+ File.join(File.dirname(__FILE__), '../../res/seriesindex.dtd'))
23
+
21
24
  if @index_file and File.file? @index_file
22
25
  parse_file(@index_file)
23
26
  end
@@ -174,11 +177,8 @@ module Sindex
174
177
  # Returns XML tree
175
178
  def build_up_xml_tree_from_index
176
179
 
177
- dtd_path = File.expand_path(
178
- File.join(File.dirname(__FILE__), '../../res/seriesindex.dtd'))
179
-
180
180
  builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
181
- xml.doc.create_internal_subset("seriesindex", nil, dtd_path)
181
+ xml.doc.create_internal_subset("seriesindex", nil, @dtd_path)
182
182
 
183
183
  xml.seriesindex {
184
184
  @series_data.sort.map do |seriesname, data|
@@ -296,6 +296,8 @@ module Sindex
296
296
  #
297
297
  # returns Nokogiri XML Document
298
298
  def open_xml_file(file)
299
+ fix_broken_dtd_path(file)
300
+
299
301
  options = Nokogiri::XML::ParseOptions::DEFAULT_XML |
300
302
  Nokogiri::XML::ParseOptions::DTDLOAD
301
303
 
@@ -313,6 +315,16 @@ module Sindex
313
315
  doc
314
316
  end
315
317
 
318
+ # Internal: fixes the path that points to the dtd file in the seriesindex
319
+ def fix_broken_dtd_path(file)
320
+ new_doctype = '<!DOCTYPE seriesindex SYSTEM "' + @dtd_path +'">'
321
+
322
+ lines = File.open(file).read
323
+ lines.gsub!(/^.*DOCTYPE.*SYSTEM.*$/, new_doctype)
324
+
325
+ File.open(file, 'w') {|f| f.write(lines) }
326
+ end
327
+
316
328
  end
317
329
 
318
330
  end
@@ -1,3 +1,3 @@
1
1
  module Sindex
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -2,15 +2,20 @@
2
2
  require File.dirname(__FILE__) + '/test_helper.rb'
3
3
  require 'fileutils'
4
4
  require 'nokogiri'
5
+ require 'tempfile'
5
6
 
6
7
  class TestIndex < Test::Unit::TestCase
7
8
 
9
+ STANDARD_SINDEX_PATH = File.dirname(__FILE__) + '/seriesindex_example.xml'
10
+ STANDARD_SINDEX_CONTENT = File.open(STANDARD_SINDEX_PATH).read
11
+
8
12
  def setup
9
- index_file = File.dirname(__FILE__) + '/seriesindex_example.xml'
10
13
 
11
- @tmp_directory = '/tmp/'
14
+ @tempfile = Tempfile.new('seriesindex')
15
+ @tempfile.puts(STANDARD_SINDEX_CONTENT)
16
+ @tempfile.flush
12
17
 
13
- @series_index = Sindex::SeriesIndex.new(index_file: index_file)
18
+ @series_index = Sindex::SeriesIndex.new(index_file: @tempfile.path)
14
19
  end
15
20
 
16
21
  def test_instantiating
@@ -21,6 +26,11 @@ class TestIndex < Test::Unit::TestCase
21
26
  assert_equal index.empty?, true
22
27
  end
23
28
 
29
+ def test_that_the_path_of_DTD_file_has_been_updated
30
+ content = File.open(@tempfile.path).read
31
+ assert_equal content.match(/^.*DOCTYPE.*\"res\/seriesindex.xml\".*$/), nil
32
+ end
33
+
24
34
  def test_parsing_a_valid_series_index
25
35
  assert_not_nil @series_index.series_data['Community']
26
36
 
@@ -68,7 +78,7 @@ class TestIndex < Test::Unit::TestCase
68
78
  end
69
79
 
70
80
  def test_that_an_index_can_be_dumped_right
71
- filename = @tmp_directory + 'dumped_index.xml'
81
+ filename = Tempfile.new('dumped_index').path
72
82
  @series_index.dump_index_to_file(filename)
73
83
 
74
84
  index = Sindex::SeriesIndex.new(index_file: filename)
@@ -96,7 +106,7 @@ class TestIndex < Test::Unit::TestCase
96
106
  end
97
107
 
98
108
  def test_that_the_all_before_flag_is_also_written_to_dumped_index
99
- filename = @tmp_directory + 'dumped_index.xml'
109
+ filename = Tempfile.new('dumped_index').path
100
110
  @series_index.dump_index_to_file(filename)
101
111
 
102
112
  doc = Nokogiri::XML(File.read(filename))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sindex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-17 00:00:00.000000000 Z
12
+ date: 2013-01-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -131,21 +131,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
131
131
  - - ! '>='
132
132
  - !ruby/object:Gem::Version
133
133
  version: '0'
134
- segments:
135
- - 0
136
- hash: 915591941571066382
137
134
  required_rubygems_version: !ruby/object:Gem::Requirement
138
135
  none: false
139
136
  requirements:
140
137
  - - ! '>='
141
138
  - !ruby/object:Gem::Version
142
139
  version: '0'
143
- segments:
144
- - 0
145
- hash: 915591941571066382
146
140
  requirements: []
147
141
  rubyforge_project:
148
- rubygems_version: 1.8.24
142
+ rubygems_version: 1.8.23
149
143
  signing_key:
150
144
  specification_version: 3
151
145
  summary: Series-Index that manages your watched episodes