rubyMorphbank 0.2.5 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/request.rb +2 -7
- data/lib/rubyMorphbank.rb +11 -11
- data/rubyMorphbank.gemspec +48 -0
- data/test/test_rubyMorphbank.rb +1 -3
- metadata +17 -13
- data/.gitignore +0 -21
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.6
|
data/lib/request.rb
CHANGED
@@ -27,20 +27,18 @@ class Request
|
|
27
27
|
:keywords => ''
|
28
28
|
}.merge!(options)
|
29
29
|
|
30
|
-
#
|
30
|
+
# Check for legal parameters
|
31
31
|
opt.keys.each do |p|
|
32
32
|
raise RubyMorphbankError, "#{p} is not a valid parameter" if !VALID_OPTIONS[opt[:version]].include?(p)
|
33
33
|
end
|
34
34
|
|
35
|
-
|
36
35
|
# TODO: add some proper sanitation?!
|
37
36
|
opt[:keywords].gsub!(/\s+/, '+') if opt[:keywords].length > 0
|
38
37
|
|
39
|
-
|
40
38
|
# create the request
|
41
39
|
@request_url = SERVICES_URI + "method=#{opt[:method]}" +
|
42
40
|
opt.keys.sort{|a,b| a.to_s <=> b.to_s}.collect{
|
43
|
-
|k| ( (URI_PARAMS.include?(k) && (!opt[k].nil? || opt[k].empty?)) ? "&#{k.to_s}=#{opt[k]}" : '')
|
41
|
+
|k| ( (URI_PARAMS.include?(k) && ( !opt[k].nil? || (opt[k] && opt[k].empty?)) ) ? "&#{k.to_s}=#{opt[k]}" : '')
|
44
42
|
}.join
|
45
43
|
|
46
44
|
# and some housekeepers
|
@@ -51,7 +49,4 @@ class Request
|
|
51
49
|
Response.new(self)
|
52
50
|
end
|
53
51
|
|
54
|
-
# .root.elements.each(xpath){}.map do |row|
|
55
|
-
|
56
|
-
## REXML::XPath.match(@xml, '//object/width').collect{|e| e.text.to_s}
|
57
52
|
end
|
data/lib/rubyMorphbank.rb
CHANGED
@@ -41,32 +41,32 @@ module RubyMorphbank
|
|
41
41
|
|
42
42
|
end
|
43
43
|
|
44
|
+
# Modified from http://snippets.dzone.com/posts/show/6181
|
44
45
|
|
45
46
|
## Base/REXML extension ##
|
46
47
|
|
47
|
-
# modified from http://snippets.dzone.com/posts/show/6181
|
48
|
-
|
49
|
-
# convert an array into a hash
|
50
|
-
class Array
|
51
|
-
def to_h
|
52
|
-
Hash[*self]
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
48
|
# neither of these extensions is particularly good, they don't recurse etc.
|
57
49
|
class REXML::Document
|
58
50
|
def record(xpath)
|
59
51
|
self.root.elements.each(xpath + '/*'){}.inject([]) do |r,node|
|
60
52
|
r << node.name.to_s << node.text.to_s.strip
|
61
|
-
end.
|
53
|
+
end.make_a_hash
|
62
54
|
end
|
63
55
|
|
64
56
|
def records(xpath)
|
65
57
|
self.root.elements.each(xpath){}.map do |row|
|
66
58
|
row.elements.each{}.inject([]) do |r,node|
|
67
59
|
r << node.name.to_s << node.text.to_s.strip
|
68
|
-
end.
|
60
|
+
end.make_a_hash
|
69
61
|
end
|
70
62
|
end
|
71
63
|
end
|
72
64
|
|
65
|
+
# Patch to convert arrays to hashes. Not the best solution at all.
|
66
|
+
class Array
|
67
|
+
def make_a_hash # don't use to_<foo>, conflicts with other nasty patchwork (e.g. Alchemist gem)
|
68
|
+
Hash[*self]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{rubyMorphbank}
|
8
|
+
s.version = "0.2.6"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["mjy"]
|
12
|
+
s.date = %q{2011-07-25}
|
13
|
+
s.description = %q{Uses the Morphbank API to query and return results from the Morphbank database.}
|
14
|
+
s.email = %q{diapriid@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.rdoc"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".document",
|
20
|
+
"README.rdoc",
|
21
|
+
"Rakefile",
|
22
|
+
"VERSION",
|
23
|
+
"init.rb",
|
24
|
+
"lib/request.rb",
|
25
|
+
"lib/response.rb",
|
26
|
+
"lib/rubyMorphbank.rb",
|
27
|
+
"rubyMorphbank.gemspec",
|
28
|
+
"test/helper.rb",
|
29
|
+
"test/test_rubyMorphbank.rb"
|
30
|
+
]
|
31
|
+
s.homepage = %q{http://github.com/mjy/rubyMorphbank}
|
32
|
+
s.require_paths = ["lib"]
|
33
|
+
s.rubygems_version = %q{1.7.2}
|
34
|
+
s.summary = %q{Simple Morphbank (http://morphbank.net) services accessor.}
|
35
|
+
|
36
|
+
if s.respond_to? :specification_version then
|
37
|
+
s.specification_version = 3
|
38
|
+
|
39
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
40
|
+
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
41
|
+
else
|
42
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
43
|
+
end
|
44
|
+
else
|
45
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
data/test/test_rubyMorphbank.rb
CHANGED
@@ -11,14 +11,13 @@ class TestRubyMorphbank < Test::Unit::TestCase
|
|
11
11
|
end
|
12
12
|
|
13
13
|
should "return an hash object using get_metadata_for_one_image" do
|
14
|
-
# WARNING: this
|
14
|
+
# WARNING: this XML2Hash is not a terribly useful conversion, the process drops all children and attributes
|
15
15
|
hash = metadata_hash_for_one_image(195815) # It's fixed data, not the best test, but if it's gone something is seriously wrong anyways
|
16
16
|
assert_equal '1360', hash['width']
|
17
17
|
end
|
18
18
|
|
19
19
|
end
|
20
20
|
|
21
|
-
|
22
21
|
class TestRequest < Test::Unit::TestCase
|
23
22
|
|
24
23
|
should "return a properly formatted request url with no options" do
|
@@ -29,7 +28,6 @@ class TestRequest < Test::Unit::TestCase
|
|
29
28
|
|
30
29
|
end
|
31
30
|
|
32
|
-
|
33
31
|
class TestResponse < Test::Unit::TestCase
|
34
32
|
|
35
33
|
should "return initialize with a unparameterized request" do
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubyMorphbank
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
9
|
+
- 6
|
10
|
+
version: 0.2.6
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- mjy
|
@@ -14,16 +15,17 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2011-
|
18
|
-
default_executable:
|
18
|
+
date: 2011-07-25 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: thoughtbot-shoulda
|
22
22
|
prerelease: false
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
24
25
|
requirements:
|
25
26
|
- - ">="
|
26
27
|
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
27
29
|
segments:
|
28
30
|
- 0
|
29
31
|
version: "0"
|
@@ -39,7 +41,6 @@ extra_rdoc_files:
|
|
39
41
|
- README.rdoc
|
40
42
|
files:
|
41
43
|
- .document
|
42
|
-
- .gitignore
|
43
44
|
- README.rdoc
|
44
45
|
- Rakefile
|
45
46
|
- VERSION
|
@@ -47,38 +48,41 @@ files:
|
|
47
48
|
- lib/request.rb
|
48
49
|
- lib/response.rb
|
49
50
|
- lib/rubyMorphbank.rb
|
51
|
+
- rubyMorphbank.gemspec
|
50
52
|
- test/helper.rb
|
51
53
|
- test/test_rubyMorphbank.rb
|
52
|
-
has_rdoc: true
|
53
54
|
homepage: http://github.com/mjy/rubyMorphbank
|
54
55
|
licenses: []
|
55
56
|
|
56
57
|
post_install_message:
|
57
|
-
rdoc_options:
|
58
|
-
|
58
|
+
rdoc_options: []
|
59
|
+
|
59
60
|
require_paths:
|
60
61
|
- lib
|
61
62
|
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
62
64
|
requirements:
|
63
65
|
- - ">="
|
64
66
|
- !ruby/object:Gem::Version
|
67
|
+
hash: 3
|
65
68
|
segments:
|
66
69
|
- 0
|
67
70
|
version: "0"
|
68
71
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
69
73
|
requirements:
|
70
74
|
- - ">="
|
71
75
|
- !ruby/object:Gem::Version
|
76
|
+
hash: 3
|
72
77
|
segments:
|
73
78
|
- 0
|
74
79
|
version: "0"
|
75
80
|
requirements: []
|
76
81
|
|
77
82
|
rubyforge_project:
|
78
|
-
rubygems_version: 1.
|
83
|
+
rubygems_version: 1.7.2
|
79
84
|
signing_key:
|
80
85
|
specification_version: 3
|
81
86
|
summary: Simple Morphbank (http://morphbank.net) services accessor.
|
82
|
-
test_files:
|
83
|
-
|
84
|
-
- test/test_rubyMorphbank.rb
|
87
|
+
test_files: []
|
88
|
+
|