ruby-dmm 0.1.2 → 0.1.3
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 +4 -4
- data/lib/ruby-dmm/client/item_list.rb +1 -0
- data/lib/ruby-dmm/response/item.rb +1 -3
- data/lib/ruby-dmm/response/item_info.rb +27 -27
- data/lib/ruby-dmm/version.rb +1 -1
- data/spec/response/item_info_spec.rb +86 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79cc74c7709505fc6927020e46facf6b3e220ac7
|
4
|
+
data.tar.gz: 0869a4633cb3da9608f81290a514ba958e57a0a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84d6e48892644274e3728a5a1ab2dd23064f75cf6f3aacd429cbd7d20113a3d82614be035a769fe94acf3e88d424650a8215353a30f1b9cc6b9624c5065334fb
|
7
|
+
data.tar.gz: 5c5e95763c5017e44177a19aade42d7b94cf65b7944a82b420edc0f56c2d29b6cb61f04daf68f6c5f214cd5cf8fdf368c098bf465224bd26226ca531d8bdb2d4
|
@@ -2,36 +2,36 @@
|
|
2
2
|
module DMM
|
3
3
|
class Response
|
4
4
|
class ItemInfo
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
:
|
10
|
-
:
|
11
|
-
:
|
12
|
-
:
|
13
|
-
:
|
14
|
-
:
|
15
|
-
|
16
|
-
|
17
|
-
:
|
18
|
-
:
|
19
|
-
:
|
20
|
-
:fighters => :fighter,
|
21
|
-
:keywords => :keyword,
|
5
|
+
|
6
|
+
# for defining
|
7
|
+
# alias_method :actors, :actor
|
8
|
+
PLURAL_MAP = {
|
9
|
+
:actor => :actors,
|
10
|
+
:actress => :actresses,
|
11
|
+
:artist => :artists,
|
12
|
+
:author => :authors,
|
13
|
+
:color => :colors,
|
14
|
+
:director => :directors,
|
15
|
+
:fighter => :fighters,
|
16
|
+
:genre => :genres,
|
17
|
+
:keyword => :keywords,
|
18
|
+
:label => :labels,
|
19
|
+
:maker => :makers,
|
22
20
|
}
|
23
|
-
attr_reader *SINGLE_VALUE_ATTRIBUTES
|
24
|
-
attr_reader *MULTIPLE_VALUES_ATTRIBUTES.keys
|
25
21
|
|
26
22
|
def initialize(item_info)
|
27
|
-
|
28
|
-
|
29
|
-
value =
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
23
|
+
item_info.each do |key, value|
|
24
|
+
key = key.to_s
|
25
|
+
value = self.class.integrate(value)
|
26
|
+
self.class.class_eval do
|
27
|
+
unless method_defined?(key)
|
28
|
+
attr_reader key
|
29
|
+
if plural = PLURAL_MAP[key.to_sym]
|
30
|
+
alias_method plural, key.to_sym
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
instance_variable_set("@#{key}", value)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
data/lib/ruby-dmm/version.rb
CHANGED
@@ -0,0 +1,86 @@
|
|
1
|
+
# vim: ts=2 sts=2 et sw=2 ft=ruby fileencoding=utf-8
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
describe DMM::Response::ItemInfo do
|
5
|
+
|
6
|
+
def complex_hash
|
7
|
+
{
|
8
|
+
"actor"=> [
|
9
|
+
{"name" => "ダニエル・ラドクリフ", "id" => "60257"},
|
10
|
+
{"name" => "だにえるらどくりふ", "id" => "60257_ruby"},
|
11
|
+
{"name" => "メガネ君", "id" => "60257_classify"},
|
12
|
+
{"name" => "ルパート・グリント", "id" => "60458"},
|
13
|
+
{"name" => "るぱーとぐりんと", "id" => "60458_ruby"},
|
14
|
+
{"name" => "リチャード・ハリス", "id" => "61833"},
|
15
|
+
{"name" => "りちゃーどはりす", "id" => "61833_ruby"},
|
16
|
+
{"name" => "エマ・ワトソン", "id" => "60074"},
|
17
|
+
{"name" => "えまわとそん", "id" => "60074_ruby"},
|
18
|
+
],
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
def simple_hash
|
23
|
+
{
|
24
|
+
"label" => {"name" => "ワーナー・ホーム・ビデオ", "id" => "60016"},
|
25
|
+
"genre" => {"name" => "ファンタジー", "id" => "71009"},
|
26
|
+
"series" => {"name" => "ハリー・ポッター", "id" => "60029"},
|
27
|
+
"maker" => {"name" => "ワーナー・ホーム・ビデオ", "id" => "45578"},
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '.integrate' do
|
32
|
+
context 'simple_hash' do
|
33
|
+
subject { DMM::Response::ItemInfo.integrate(complex_hash["actor"]) }
|
34
|
+
it 'integrates name and ruby and more (classify etc...) by id' do
|
35
|
+
actor = subject.find {|actor| actor["id"] == "60257" }
|
36
|
+
actor["name"].should == "ダニエル・ラドクリフ"
|
37
|
+
actor["ruby"].should == "だにえるらどくりふ"
|
38
|
+
actor["classify"].should == "メガネ君"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'simple_hash' do
|
43
|
+
subject { DMM::Response::ItemInfo.integrate(simple_hash["label"]) }
|
44
|
+
it 'runs collectry' do
|
45
|
+
label = subject.first
|
46
|
+
label["id"].should == "60016"
|
47
|
+
label["name"].should == "ワーナー・ホーム・ビデオ"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
describe 'define method for any keys' do
|
54
|
+
context 'complex_hash' do
|
55
|
+
subject { DMM::Response::ItemInfo.new(complex_hash) }
|
56
|
+
its(:actors) { should_not be_empty }
|
57
|
+
describe 'actors' do
|
58
|
+
it 'integrates name and ruby by id' do
|
59
|
+
actor = subject.actors.find {|actor| actor["id"] == "60257" }
|
60
|
+
actor["name"].should == "ダニエル・ラドクリフ"
|
61
|
+
actor["ruby"].should == "だにえるらどくりふ"
|
62
|
+
actor["classify"].should == "メガネ君"
|
63
|
+
|
64
|
+
actor = subject.actors.find {|actor| actor["id"] == "60074" }
|
65
|
+
actor["name"].should == "エマ・ワトソン"
|
66
|
+
actor["ruby"].should == "えまわとそん"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'simple_hash' do
|
72
|
+
subject do
|
73
|
+
DMM::Response::ItemInfo.new(simple_hash)
|
74
|
+
end
|
75
|
+
it { should be }
|
76
|
+
|
77
|
+
describe 'director' do
|
78
|
+
it 'respond to given keys' do
|
79
|
+
simple_hash.keys.each do |key|
|
80
|
+
subject.should respond_to(key)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-dmm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- meganemura
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -115,6 +115,7 @@ files:
|
|
115
115
|
- spec/fixtures/r18_rental.xml
|
116
116
|
- spec/fixtures/request_error.xml
|
117
117
|
- spec/fixtures/zero_items.xml
|
118
|
+
- spec/response/item_info_spec.rb
|
118
119
|
- spec/response/item_spec.rb
|
119
120
|
- spec/response_spec.rb
|
120
121
|
- spec/spec_helper.rb
|
@@ -164,6 +165,7 @@ test_files:
|
|
164
165
|
- spec/fixtures/r18_rental.xml
|
165
166
|
- spec/fixtures/request_error.xml
|
166
167
|
- spec/fixtures/zero_items.xml
|
168
|
+
- spec/response/item_info_spec.rb
|
167
169
|
- spec/response/item_spec.rb
|
168
170
|
- spec/response_spec.rb
|
169
171
|
- spec/spec_helper.rb
|