risbn 0.3.0 → 0.4.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.3.0
1
+ 0.4.0
data/lib/risbn/gdata.rb CHANGED
@@ -44,7 +44,7 @@ class RISBN
44
44
  # returns an openstruct with a massaged version of the original xml data.
45
45
  def data
46
46
  return @data if @data
47
- h, data = to_hash, OpenStruct.new
47
+ h, data = to_hash, BookData.new
48
48
 
49
49
  data.creator = h[:creator]
50
50
  data.date = h[:date]
@@ -74,6 +74,15 @@ class RISBN
74
74
  @data = data
75
75
  end
76
76
 
77
+ class BookData < OpenStruct
78
+ def to_hash
79
+ @table.dup
80
+ end
81
+
82
+ def keys
83
+ @table.keys
84
+ end
85
+ end
77
86
  end
78
87
  end
79
88
 
data/lib/risbn/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class RISBN
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
data/risbn.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{risbn}
8
- s.version = "0.3.0"
8
+ s.version = "0.4.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Emmanuel Oga"]
data/spec/gdata_spec.rb CHANGED
@@ -16,23 +16,28 @@ describe RISBN::GData do
16
16
  expect { RISBN::GData(RISBN("6660596101992")) }.to raise_exception(RISBN::InvalidISBN)
17
17
  end
18
18
 
19
- context "retrieving gdata" do
20
- before do
21
- @isbn = RISBN("9780596101992")
22
- @isbn.gdata.stub!(:xml).and_return(File.read(GDATA_FIXTURE_PATH))
23
- end
19
+ context "#data" do
20
+ let(:isbn) { RISBN("9780596101992") }
21
+ before { isbn.gdata.stub!(:xml).and_return(File.read(GDATA_FIXTURE_PATH)) }
24
22
 
25
- it "returns an OpenStruct" do
26
- @isbn.gdata.data.should be_an_instance_of(OpenStruct)
23
+ let(:required_keys) do
24
+ more = [:open_access, :rating_max, :rating_min, :thumbnail_url,
25
+ :info_url, :annotation_url, :alternate_url, :self_url]
26
+ isbn.gdata.to_hash.keys.uniq - [:link, :openAccess] + more
27
27
  end
28
28
 
29
- it "maps the attributes of the hash form of google response to an struct" do
30
- additional_keys = [:open_access, :rating_max, :rating_min, :thumbnail_url,
31
- :info_url, :annotation_url, :alternate_url, :self_url]
29
+ subject { isbn.gdata.data }
30
+
31
+ it { should be_an_instance_of(RISBN::GData::BookData) }
32
+
33
+ it "maps the attributes of the hash form of the google response to an struct" do
34
+ required_keys.each { |key| should respond_to(key) }
35
+ end
32
36
 
33
- ( @isbn.gdata.to_hash.keys.uniq - [:link, :openAccess] + additional_keys).each do |key|
34
- @isbn.gdata.data.should respond_to(key)
35
- end
37
+ it "is able to convert the struct to a hash and return its keys" do
38
+ isbn.gdata.data.to_hash.should be_an_instance_of(Hash)
39
+ isbn.gdata.data.keys.should be_an_instance_of(Array)
40
+ isbn.gdata.data.keys.should_not be_empty
36
41
  end
37
42
  end
38
43
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 3
7
+ - 4
8
8
  - 0
9
- version: 0.3.0
9
+ version: 0.4.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Emmanuel Oga