ndl 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +23 -2
- data/lib/ndl/opensearch.rb +17 -0
- data/lib/ndl/version.rb +1 -1
- data/test.rb +15 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed4b38185946ee7f80fa6a6cc9095e943eb4933c
|
4
|
+
data.tar.gz: 738c66008b2884c819e74acf6f0d1a3877261ffb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e986c7decd65b65182c302d0145619b1486003303f895e2344bcd3ac4701b238f2b9211c332998f031c5487d5a0ab00b56aa2d6dc7da5924475205516984fbe8
|
7
|
+
data.tar.gz: cd7a71595819b808d0e83448a1c55ec3b2f4a554288cd9c26c86a3865c68d10dd97724c0c389cd68398801506f08bf54ab200dc599f76bf2944c41861f0cead2
|
data/README.md
CHANGED
@@ -39,9 +39,30 @@ Or install it yourself as:
|
|
39
39
|
- :isbn
|
40
40
|
- :mediatype
|
41
41
|
|
42
|
+
* please refer to [my repository](https://github.com/himkt/opensearch)
|
43
|
+
|
42
44
|
```ruby
|
43
|
-
|
44
|
-
|
45
|
+
require 'ndl'
|
46
|
+
|
47
|
+
open_search = Ndl::OpenSearch.new
|
48
|
+
|
49
|
+
|
50
|
+
# you can parse 'result' by using xml parser
|
51
|
+
result = open_search.search(:title=>'a', :from=>'1111-11-11', :cnt=>2, :ndc=>100)
|
52
|
+
|
53
|
+
# parse return Hash include key, 'hit' and 'item'
|
54
|
+
# hit is number of hit
|
55
|
+
# item is array that include hash object, and array include bibliography
|
56
|
+
parsed_result = open_search.parse(result)
|
57
|
+
p parsed_result
|
58
|
+
|
59
|
+
=begin
|
60
|
+
# you can also see result by using the following code
|
61
|
+
result = open_search.search(:title=>'a', :from=>'1111-11-11', :cnt=>2)
|
62
|
+
while line = result.gets
|
63
|
+
puts line
|
64
|
+
end
|
65
|
+
=end
|
45
66
|
```
|
46
67
|
|
47
68
|
## Development
|
data/lib/ndl/opensearch.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'open-uri'
|
2
|
+
require 'rss'
|
2
3
|
|
3
4
|
module Ndl
|
4
5
|
class OpenSearch
|
@@ -18,5 +19,21 @@ module Ndl
|
|
18
19
|
result = open(@url)
|
19
20
|
return result
|
20
21
|
end
|
22
|
+
def parse(result)
|
23
|
+
parsed_result = Hash.new
|
24
|
+
doc = RSS::Parser.parse(result)
|
25
|
+
parsed_result[:hit] = doc.items.size
|
26
|
+
parsed_result[:item] = Array.new
|
27
|
+
doc.items.each do |item|
|
28
|
+
bibliography = Hash.new
|
29
|
+
bibliography[:dc_title] = item.dc_title
|
30
|
+
bibliography[:dc_creator] = item.dc_creator
|
31
|
+
bibliography[:guid] = item.guid.content
|
32
|
+
bibliography[:category] = item.category.content
|
33
|
+
bibliography[:dc_subject] = item.dc_subject if item.dc_subject.size == 3
|
34
|
+
parsed_result[:item].push(bibliography)
|
35
|
+
end
|
36
|
+
return parsed_result
|
37
|
+
end
|
21
38
|
end
|
22
39
|
end
|
data/lib/ndl/version.rb
CHANGED
data/test.rb
CHANGED
@@ -1,9 +1,23 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
1
2
|
require 'ndl'
|
2
3
|
|
3
4
|
open_search = Ndl::OpenSearch.new
|
4
5
|
|
5
|
-
result = open_search.search(:title=>'a', :from=>'1111-11-11', :cnt=>2)
|
6
6
|
|
7
|
+
# you can parse 'result' by using xml parser
|
8
|
+
result = open_search.search(:title=>'a', :from=>'1111-11-11', :cnt=>2, :ndc=>100)
|
9
|
+
|
10
|
+
# parse return Hash include key, 'hit' and 'item'
|
11
|
+
# hit is number of hit
|
12
|
+
# item is array that include hash object, and array include bibliography
|
13
|
+
parsed_result = open_search.parse(result)
|
14
|
+
p parsed_result[:hit]
|
15
|
+
p parsed_result[:item]
|
16
|
+
|
17
|
+
=begin
|
18
|
+
# you can also see result by using the following code
|
19
|
+
result = open_search.search(:title=>'a', :from=>'1111-11-11', :cnt=>2)
|
7
20
|
while line = result.gets
|
8
21
|
puts line
|
9
22
|
end
|
23
|
+
=end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ndl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Makoto Hiramatsu
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|