djatoka 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.9
1
+ 0.0.10
@@ -15,7 +15,7 @@ Usage:
15
15
  where options are:
16
16
  EOS
17
17
  opt :resolver, "A Djatoka resolver base URL", :required => true, :type => String
18
- opt :rftid, "Resource identifier", :required => true, :type => String, :short => :i
18
+ opt :rftid, "Resource identifier", :type => String, :short => :i
19
19
  opt :level, 'Level', :type => String
20
20
  opt :rotate, 'Rotate', :type => String
21
21
  opt :region, 'Region', :type => String
@@ -29,47 +29,65 @@ EOS
29
29
  opt :square, 'Squares the image by cropping both sides'
30
30
  opt :topleftsquare, 'Squares the image by justifying to the top left'
31
31
  opt :bottomrightsquare, 'Squares the image by jutifying to the bottom right'
32
+ opt :file, 'process a whole file of rtfids', :type => String
32
33
  end
33
34
 
34
- resolver = Djatoka::Resolver.new(opts[:resolver])
35
- region = resolver.region(opts[:rftid])
36
-
37
- [:level, :rotate, :region, :scale, :format, :clayer].each do |param|
38
- region.send(param, opts[param]) if opts[param]
35
+ if (!opts[:rftid] and !opts[:file]) or (opts[:rftid] and opts[:file])
36
+ Trollop::die :rftid, "You must specify either --rftid or --file"
39
37
  end
40
38
 
41
- if opts[:smallbox]
42
- region.smallbox
39
+ if opts[:rftid]
40
+ rftids = [opts[:rftid]]
41
+ elsif opts[:file]
42
+ Trollop::die :file, "File must exist" if !File.exists?(opts[:file])
43
+ rftids = File.read(opts[:file]).split("\n")
43
44
  end
44
45
 
45
- if opts[:square]
46
- region.square
47
- end
46
+ resolver = Djatoka::Resolver.new(opts[:resolver])
48
47
 
49
- if opts[:topleftsquare]
50
- region.top_left_square
51
- end
48
+ rftids.each do |rftid|
49
+ region = resolver.region(rftid)
52
50
 
53
- if opts[:bottomrightsquare]
54
- region.bottom_right_square
55
- end
51
+ [:level, :rotate, :region, :scale, :format, :clayer].each do |param|
52
+ region.send(param, opts[param]) if opts[param]
53
+ end
56
54
 
57
- if opts[:metadata] or opts[:levels]
58
- metadata = resolver.metadata(opts[:rftid])
59
- metadata.perform
60
- if opts[:metadata]
61
- puts metadata.url
62
- `#{opts[:browser]} "#{metadata.url}"` if opts[:browser]
63
- pp metadata.response
64
- end
65
- if opts[:levels]
66
- pp metadata.all_levels
67
- end
68
- end
55
+ if opts[:smallbox]
56
+ region.smallbox
57
+ end
58
+
59
+ if opts[:square]
60
+ region.square
61
+ end
62
+
63
+ if opts[:topleftsquare]
64
+ region.top_left_square
65
+ end
69
66
 
70
- pp region.query
67
+ if opts[:bottomrightsquare]
68
+ region.bottom_right_square
69
+ end
71
70
 
72
- puts region.url
71
+ if opts[:metadata] or opts[:levels]
72
+ metadata = resolver.metadata(rftid)
73
+ metadata.perform
74
+ if opts[:metadata]
75
+ puts metadata.url unless opts[:file]
76
+ `#{opts[:browser]} "#{metadata.url}"` if opts[:browser]
77
+ pp metadata.response #unless opts[:file]
78
+ if metadata.response.nil? or metadata.response.empty?
79
+ pp rftid + ": empty"
80
+ end
81
+ end
82
+ if opts[:levels]
83
+ pp metadata.all_levels unless opts[:file]
84
+ end
85
+ end
73
86
 
74
- `#{opts[:browser]} "#{region.url}"` if opts[:browser]
87
+ pp region.query unless opts[:file]
88
+
89
+ puts region.url unless opts[:file]
90
+
91
+ `#{opts[:browser]} "#{region.url}"` if opts[:browser]
92
+ end
75
93
 
@@ -90,7 +90,11 @@ module Djatoka::Common
90
90
  # seen so far.
91
91
  def square_params(justify = :center)
92
92
  metadata = Djatoka::Metadata.new(resolver, rft_id).perform
93
- if metadata
93
+ # since nil.to_i #=> 0
94
+ # check that height and width are present otherwise our calculations will
95
+ # fail and raise an error. We want to avoid that and would rather show a
96
+ # broken image than raise--at least for now.
97
+ if metadata.height and metadata.width
94
98
  orig_height = metadata.height.to_i
95
99
  orig_width = metadata.width.to_i
96
100
  if query.scale and query.scale.split.length == 1
@@ -38,4 +38,6 @@ end
38
38
 
39
39
  FakeWeb.register_uri(:get, "http://african.lanl.gov/adore-djatoka/resolver?rft_id=ua023_015-006-bx0003-014-075&svc_id=info%3Alanl-repo%2Fsvc%2FgetMetadata&url_ver=Z39.88-2004",
40
40
  :response => File.read('test/fixtures/ua023_015-006-bx0003-014-075-metadata.json'))
41
-
41
+
42
+ FakeWeb.register_uri(:get, "http://african.lanl.gov/adore-djatoka/resolver?rft_id=asdf&svc_id=info%3Alanl-repo%2Fsvc%2FgetMetadata&url_ver=Z39.88-2004",
43
+ :response => File.read('test/fixtures/empty-metadata.json'))
@@ -79,6 +79,16 @@ context 'A Djatoka Resolver' do
79
79
  assert @region2.url
80
80
  end
81
81
  end
82
+
83
+ context 'an request for a non-existent image' do
84
+ setup do
85
+ @no_region = Djatoka::Region.new(@resolver, 'asdf')
86
+ end
87
+ should 'not raise when no metadata and trying to create a square at scale' do
88
+ @no_region.scale(300).square
89
+ assert @no_region.url
90
+ end
91
+ end
82
92
 
83
93
  end
84
94
 
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: 13
4
+ hash: 11
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 9
10
- version: 0.0.9
9
+ - 10
10
+ version: 0.0.10
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-11-02 00:00:00 -04:00
18
+ date: 2010-11-15 00:00:00 -05:00
19
19
  default_executable: djatoka_url
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency