djatoka 0.0.10 → 0.0.11
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.
- data/VERSION +1 -1
- data/bin/djatoka_url +11 -0
- data/lib/djatoka/common.rb +1 -1
- data/lib/djatoka/metadata.rb +7 -3
- data/test/test_common.rb +3 -3
- data/test/test_metadata.rb +17 -11
- metadata +14 -14
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.11
|
data/bin/djatoka_url
CHANGED
@@ -3,6 +3,7 @@ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
|
3
3
|
require 'djatoka'
|
4
4
|
require 'trollop'
|
5
5
|
require 'pp'
|
6
|
+
require 'open-uri'
|
6
7
|
|
7
8
|
opts = Trollop::options do
|
8
9
|
banner <<-EOS
|
@@ -30,6 +31,7 @@ EOS
|
|
30
31
|
opt :topleftsquare, 'Squares the image by justifying to the top left'
|
31
32
|
opt :bottomrightsquare, 'Squares the image by jutifying to the bottom right'
|
32
33
|
opt :file, 'process a whole file of rtfids', :type => String
|
34
|
+
opt :download, 'download the image to the current working directory'
|
33
35
|
end
|
34
36
|
|
35
37
|
if (!opts[:rftid] and !opts[:file]) or (opts[:rftid] and opts[:file])
|
@@ -43,6 +45,7 @@ elsif opts[:file]
|
|
43
45
|
rftids = File.read(opts[:file]).split("\n")
|
44
46
|
end
|
45
47
|
|
48
|
+
|
46
49
|
resolver = Djatoka::Resolver.new(opts[:resolver])
|
47
50
|
|
48
51
|
rftids.each do |rftid|
|
@@ -89,5 +92,13 @@ rftids.each do |rftid|
|
|
89
92
|
puts region.url unless opts[:file]
|
90
93
|
|
91
94
|
`#{opts[:browser]} "#{region.url}"` if opts[:browser]
|
95
|
+
|
96
|
+
if opts[:download]
|
97
|
+
puts 'downloading...'
|
98
|
+
image = open(region.url).read
|
99
|
+
File.open(rftid + '.jpg', 'w') do |fh|
|
100
|
+
fh.puts image
|
101
|
+
end
|
102
|
+
end
|
92
103
|
end
|
93
104
|
|
data/lib/djatoka/common.rb
CHANGED
@@ -64,7 +64,7 @@ module Djatoka::Common
|
|
64
64
|
# try to compensate for any difference between the dwtLevels and djatoka levels
|
65
65
|
# so that we get a decent image returned.
|
66
66
|
def pick_best_level(metadata)
|
67
|
-
best_level =
|
67
|
+
best_level = metadata.max_level
|
68
68
|
metadata_levels = metadata.all_levels
|
69
69
|
metadata_levels.keys.sort.reverse.each do |k|
|
70
70
|
if metadata_levels[k].height.to_i > query.scale.to_i and
|
data/lib/djatoka/metadata.rb
CHANGED
@@ -56,21 +56,25 @@ class Djatoka::Metadata
|
|
56
56
|
def all_levels
|
57
57
|
perform if !response # if we haven't already performed the metadata query do it now
|
58
58
|
levels_hash = Hashie::Mash.new
|
59
|
-
levels_i = levels.to_i
|
59
|
+
levels_i = levels.to_i
|
60
60
|
(0..levels_i).each do |level_num|
|
61
61
|
level_height = height.to_i
|
62
62
|
level_width = width.to_i
|
63
63
|
|
64
64
|
times_to_halve = levels_i - level_num
|
65
65
|
times_to_halve.times do
|
66
|
-
level_height = level_height / 2
|
67
|
-
level_width = level_width / 2
|
66
|
+
level_height = (level_height / 2.0).round
|
67
|
+
level_width = (level_width / 2.0).round
|
68
68
|
end
|
69
69
|
|
70
70
|
levels_hash[level_num] = {:height => level_height, :width => level_width}
|
71
71
|
end
|
72
72
|
levels_hash
|
73
73
|
end
|
74
|
+
|
75
|
+
def max_level
|
76
|
+
all_levels.keys.sort.last
|
77
|
+
end
|
74
78
|
|
75
79
|
end
|
76
80
|
|
data/test/test_common.rb
CHANGED
@@ -8,18 +8,18 @@ context 'A Djatoka Resolver' do
|
|
8
8
|
@region = Djatoka::Region.new(@resolver, @identifier)
|
9
9
|
end
|
10
10
|
should 'create a query for a 75x75 version of the image' do
|
11
|
-
assert_equal '0,874,
|
11
|
+
assert_equal '0,874,106,106', @region.smallbox.query.region
|
12
12
|
assert_equal '75', @region.smallbox.query.scale
|
13
13
|
end
|
14
14
|
|
15
15
|
should 'return a String for a smallbox URL' do
|
16
16
|
assert @region.smallbox_url.is_a? String
|
17
17
|
assert @region.smallbox_url.include? 'http://african.lanl.gov'
|
18
|
-
assert @region.smallbox_url.include? 'svc.region=0%2C874%
|
18
|
+
assert @region.smallbox_url.include? 'svc.region=0%2C874%2C106%2C106'
|
19
19
|
end
|
20
20
|
|
21
21
|
should 'return a uri for a small square version of the image' do
|
22
|
-
assert_equal '0,874,
|
22
|
+
assert_equal '0,874,106,106', @region.smallbox.uri.query_values['svc.region']
|
23
23
|
end
|
24
24
|
|
25
25
|
should 'create a query for a square version of the image' do
|
data/test/test_metadata.rb
CHANGED
@@ -66,21 +66,28 @@ class TestDjatokaMetadata < Test::Unit::TestCase
|
|
66
66
|
@metadata = @metadata_obj.perform
|
67
67
|
@levels = @metadata.all_levels
|
68
68
|
end
|
69
|
+
should 'create the number of metadata levels as djatoka provides' do
|
70
|
+
assert_equal 7, @levels.length
|
71
|
+
end
|
69
72
|
should 'return height and width for all levels' do
|
70
|
-
|
71
|
-
"1"=>{"height"=>
|
72
|
-
"2"=>{"height"=>
|
73
|
-
"3"=>{"height"=>
|
73
|
+
expected_levels = { "0"=>{"height"=>53, "width"=>80},
|
74
|
+
"1"=>{"height"=>106, "width"=>160},
|
75
|
+
"2"=>{"height"=>211, "width"=>320},
|
76
|
+
"3"=>{"height"=>422, "width"=>640},
|
74
77
|
"4"=>{"height"=>843, "width"=>1280},
|
75
78
|
"5"=>{"height"=>1686, "width"=>2560},
|
76
|
-
"6"=>{"height"=>3372, "width"=>5120}
|
77
|
-
assert_equal
|
79
|
+
"6"=>{"height"=>3372, "width"=>5120}}
|
80
|
+
assert_equal expected_levels, @levels
|
81
|
+
end
|
82
|
+
should 'know which is the max level' do
|
83
|
+
assert_equal "6", @metadata.max_level
|
78
84
|
end
|
85
|
+
|
79
86
|
should 'return appropriate height and width for all levels when levels and dwt_levels do not match' do
|
80
|
-
levels = {"0"=>{"height"=>
|
81
|
-
"1"=>{"height"=>
|
82
|
-
"2"=>{"height"=>
|
83
|
-
"3"=>{"height"=>
|
87
|
+
levels = {"0"=>{"height"=>58, "width"=>37},
|
88
|
+
"1"=>{"height"=>115, "width"=>74},
|
89
|
+
"2"=>{"height"=>229, "width"=>148},
|
90
|
+
"3"=>{"height"=>458, "width"=>296},
|
84
91
|
"4"=>{"height"=>915, "width"=>592}}
|
85
92
|
metadata = @resolver.metadata('ua023_015-006-bx0003-014-075').perform
|
86
93
|
returned_levels = metadata.all_levels
|
@@ -88,7 +95,6 @@ class TestDjatokaMetadata < Test::Unit::TestCase
|
|
88
95
|
|
89
96
|
end
|
90
97
|
|
91
|
-
|
92
98
|
end # levels
|
93
99
|
|
94
100
|
end #with_a_resolver
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: djatoka
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 9
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 11
|
10
|
+
version: 0.0.11
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jason Ronallo
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-12-21 00:00:00 -05:00
|
19
19
|
default_executable: djatoka_url
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -167,20 +167,20 @@ files:
|
|
167
167
|
- lib/djatoka/region.rb
|
168
168
|
- lib/djatoka/resolver.rb
|
169
169
|
- lib/djatoka/view_helpers.rb
|
170
|
-
- test/
|
170
|
+
- test/helper.rb
|
171
|
+
- test/test_common.rb
|
171
172
|
- test/test_djatoka.rb
|
173
|
+
- test/test_metadata.rb
|
174
|
+
- test/test_region.rb
|
172
175
|
- test/test_resolver.rb
|
173
176
|
- test/test_view_helpers.rb
|
174
|
-
- test/test_region.rb
|
175
|
-
- test/helper.rb
|
176
|
-
- test/test_common.rb
|
177
177
|
has_rdoc: true
|
178
178
|
homepage: http://github.com/jronallo/djatoka
|
179
179
|
licenses: []
|
180
180
|
|
181
181
|
post_install_message:
|
182
|
-
rdoc_options:
|
183
|
-
|
182
|
+
rdoc_options: []
|
183
|
+
|
184
184
|
require_paths:
|
185
185
|
- lib
|
186
186
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -209,10 +209,10 @@ signing_key:
|
|
209
209
|
specification_version: 3
|
210
210
|
summary: Djatoka image server helpers for Ruby and Rails.
|
211
211
|
test_files:
|
212
|
-
- test/
|
212
|
+
- test/helper.rb
|
213
|
+
- test/test_common.rb
|
213
214
|
- test/test_djatoka.rb
|
215
|
+
- test/test_metadata.rb
|
216
|
+
- test/test_region.rb
|
214
217
|
- test/test_resolver.rb
|
215
218
|
- test/test_view_helpers.rb
|
216
|
-
- test/test_region.rb
|
217
|
-
- test/helper.rb
|
218
|
-
- test/test_common.rb
|