tvdb 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.1.0
@@ -22,18 +22,26 @@ module TVdb
22
22
  protected
23
23
 
24
24
  def attributes_from_xml(xml)
25
- return {} if xml.nil? || xml.empty?
26
- doc = Hpricot(xml)
27
-
28
25
  attributes = {}
26
+ return attributes if xml.nil? || xml.is_a?(String) && xml.empty?
27
+
28
+ element_root = if xml.is_a?(Hpricot::Elem)
29
+ xml
30
+ else
31
+ doc = xml.is_a?(Hpricot::Doc) ? xml : Hpricot(xml)
32
+
33
+ # doc.children.nil? is true for Hpricot('')
34
+ doc.children.nil? ? doc : (@root_name.nil? ? doc.root : doc.search(@root_name).first)
35
+ end
29
36
 
30
- element_root = @root_name.nil? ? doc.root : doc.search(@root_name).first
31
-
32
- element_root.children.map do |child|
33
- unless child.is_a?(Hpricot::Text)
34
- attributes[child.name] = child.inner_text
37
+ if element_root.children
38
+ element_root.children.map do |child|
39
+ unless child.is_a?(Hpricot::Text)
40
+ attributes[child.name] = child.inner_text
41
+ end
35
42
  end
36
43
  end
44
+
37
45
  attributes
38
46
  end
39
47
  end
@@ -1,7 +1,11 @@
1
1
  module TVdb
2
2
  class Serie < Element
3
+ attr_accessor :episodes
4
+
3
5
  def initialize(xml)
4
- super(xml, 'series') do |atts|
6
+ doc = Hpricot(xml)
7
+
8
+ super(doc, 'series') do |atts|
5
9
  # Turn into arrays
6
10
  atts["actors"] = atts["actors"].split('|').select{|a| !a.nil? && !a.empty?} if atts["actors"] && atts["actors"].is_a?(String) && !atts["actors"].empty?
7
11
  genres = atts.delete("genre")
@@ -9,6 +13,8 @@ module TVdb
9
13
 
10
14
  atts["poster"] = BANNER_URL % atts["poster"] unless atts["poster"].nil?
11
15
  end
16
+
17
+ @episodes = doc.search('episode').map{|exml| Element.new(exml)}
12
18
  end
13
19
  end
14
20
 
@@ -11,5 +11,7 @@ def load_example_data
11
11
  @serie2_xml = File.read(File.dirname(__FILE__) + "/data/serie2.xml")
12
12
  @series_xml = @serie1_xml + @serie2_xml
13
13
  @serie1_zip = File.open(File.dirname(__FILE__) + "/data/serie1.zip")
14
+ @serie1_full_xml = Zip::ZipFile.new(@serie1_zip.path).find_entry("en.xml").get_input_stream.read
14
15
  @serie2_zip = File.open(File.dirname(__FILE__) + "/data/serie2.zip")
16
+ @serie2_full_xml = Zip::ZipFile.new(@serie2_zip.path).find_entry("en.xml").get_input_stream.read
15
17
  end
@@ -42,8 +42,28 @@ module TVdb
42
42
 
43
43
  it "should behave with empty xml" do
44
44
  element = Element.new("")
45
-
46
45
  element.wadus.should be_nil
47
46
  end
47
+
48
+ it "should accept already parsed Hpricot documents" do
49
+ element = Element.new(Hpricot('<Element><attribute1>The one</attribute1><second>2</second><last>inphinity</last></Element>'))
50
+ element.attribute1.should == "The one"
51
+ element.second.should == "2"
52
+ element.last.should == "inphinity"
53
+ end
54
+
55
+ it "should accept already parsed Hpricot elements" do
56
+ doc = Hpricot('<Doc><Element><attribute1>The one</attribute1><second>2</second><last>inphinity</last></Element></Doc>')
57
+ element = Element.new(doc.search('element').first)
58
+ element.attribute1.should == "The one"
59
+ element.second.should == "2"
60
+ element.last.should == "inphinity"
61
+ end
62
+
63
+ it "should behave with empty Hpricot::Doc objects" do
64
+ element = Element.new(Hpricot(''))
65
+ element.wadus.should be_nil
66
+ end
67
+
48
68
  end
49
69
  end
@@ -35,5 +35,21 @@ module TVdb
35
35
  serie.poster.should == TVdb::BANNER_URL % "posters/80379-1.jpg"
36
36
  end
37
37
 
38
+ it "should parse episodes and return them as an array of Element objects" do
39
+ serie = Serie.new(@serie1_full_xml)
40
+
41
+ serie.episodes.size.should == 55 # There are 55 <Episode> tags in the zip file
42
+
43
+ serie.episodes.first.tvdb_id.should == '1102131'
44
+ serie.episodes.first.episodename.should == 'Physicist To The Stars'
45
+ serie.episodes.first.seriesid.should == serie.tvdb_id
46
+
47
+ serie.episodes[1].tvdb_id.should == '1088021'
48
+ serie.episodes[1].episodename.should == 'Season 2 Gag Reel'
49
+
50
+ serie.episodes.last.tvdb_id.should == '1309961'
51
+ serie.episodes.last.episodename.should == 'The Maternal Congruence'
52
+ end
53
+
38
54
  end
39
55
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{tvdb}
8
- s.version = "0.0.2"
8
+ s.version = "0.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["\303\201lvaro Bautista"]
@@ -42,7 +42,7 @@ Gem::Specification.new do |s|
42
42
  s.homepage = %q{http://github.com/alvarobp/tvdb}
43
43
  s.rdoc_options = ["--charset=UTF-8"]
44
44
  s.require_paths = ["lib"]
45
- s.rubygems_version = %q{1.3.6}
45
+ s.rubygems_version = %q{1.3.7}
46
46
  s.summary = %q{Ruby wrapper for TheTVDB}
47
47
  s.test_files = [
48
48
  "spec/spec_helper.rb",
@@ -56,7 +56,7 @@ Gem::Specification.new do |s|
56
56
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
57
57
  s.specification_version = 3
58
58
 
59
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
59
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
60
60
  s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
61
61
  s.add_runtime_dependency(%q<hpricot>, [">= 0.8.1"])
62
62
  s.add_runtime_dependency(%q<rubyzip>, [">= 0.9.1"])
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tvdb
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 27
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
8
+ - 1
7
9
  - 0
8
- - 2
9
- version: 0.0.2
10
+ version: 0.1.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - "\xC3\x81lvaro Bautista"
@@ -21,9 +22,11 @@ dependencies:
21
22
  name: rspec
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - ">="
26
28
  - !ruby/object:Gem::Version
29
+ hash: 13
27
30
  segments:
28
31
  - 1
29
32
  - 2
@@ -35,9 +38,11 @@ dependencies:
35
38
  name: hpricot
36
39
  prerelease: false
37
40
  requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
38
42
  requirements:
39
43
  - - ">="
40
44
  - !ruby/object:Gem::Version
45
+ hash: 61
41
46
  segments:
42
47
  - 0
43
48
  - 8
@@ -49,9 +54,11 @@ dependencies:
49
54
  name: rubyzip
50
55
  prerelease: false
51
56
  requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
52
58
  requirements:
53
59
  - - ">="
54
60
  - !ruby/object:Gem::Version
61
+ hash: 57
55
62
  segments:
56
63
  - 0
57
64
  - 9
@@ -100,23 +107,27 @@ rdoc_options:
100
107
  require_paths:
101
108
  - lib
102
109
  required_ruby_version: !ruby/object:Gem::Requirement
110
+ none: false
103
111
  requirements:
104
112
  - - ">="
105
113
  - !ruby/object:Gem::Version
114
+ hash: 3
106
115
  segments:
107
116
  - 0
108
117
  version: "0"
109
118
  required_rubygems_version: !ruby/object:Gem::Requirement
119
+ none: false
110
120
  requirements:
111
121
  - - ">="
112
122
  - !ruby/object:Gem::Version
123
+ hash: 3
113
124
  segments:
114
125
  - 0
115
126
  version: "0"
116
127
  requirements: []
117
128
 
118
129
  rubyforge_project:
119
- rubygems_version: 1.3.6
130
+ rubygems_version: 1.3.7
120
131
  signing_key:
121
132
  specification_version: 3
122
133
  summary: Ruby wrapper for TheTVDB