iiif_url 0.0.1 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0619253ce49f6b4de78e3743e69d2507ce5ae99d
4
- data.tar.gz: c7c71e6ec3ddb6d6c349590e129ceb87f7e5f58e
3
+ metadata.gz: d53ebf5b4faff0adc10e4c6c4eab1b536fefcb7f
4
+ data.tar.gz: eaf05909652d3e33da4402ac6c52a78c66ca1d93
5
5
  SHA512:
6
- metadata.gz: 988c43d7edaa08efd7470329c58ebd2d2ecdedc2a9fa0f715d5b4cec2b2ab4cdadba01117e7361ae143004334bcc68af6a36ea56d6fd5e564a2b2c98c2f1cdc6
7
- data.tar.gz: feec5e94df362c77e59a61f32a828c00ffd75be4b9b555a16b221894d4e78c6d7b43cdbebde73f63cddf5742a83d8bd1d96d2826ee258b5baa876d08ec4548d4
6
+ metadata.gz: 2a98fd31dad51dc0fff1f29ad1f5ac6432182b8c4f833da2bf47d2bfe8bc03a6ac03c18468da3bc589235997404bda7b97b514f88223abe08ca951d01afe4463
7
+ data.tar.gz: bd9c51c255f47aefded64f4aa4768a5dc03a74757aeb6ad31c2ef5ae4578b8c9e2d8026c36b61455273fac168188c1edcde23890a0fac292114cfc8c4c58a4bf
data/README.md CHANGED
@@ -20,11 +20,11 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- Here's the simplest case of creating a IIIF URL with all options. By default only the path is given without the scheme, server, port, or IIIF prefix.
23
+ Here's the simplest case of creating a IIIF URL with all params. By default only the path is given without the scheme, server, port, or IIIF prefix.
24
24
 
25
25
  ```ruby
26
26
  iiif_base_url = "http://example.edu/prefix"
27
- options = {
27
+ params = {
28
28
  identifier: 'abc',
29
29
  region: 'full',
30
30
  size: 'full',
@@ -32,17 +32,17 @@ options = {
32
32
  quality: 'default',
33
33
  format: 'jpg'
34
34
  }
35
- url = IiifUrl.from_options(options)
35
+ url = IiifUrl.from_params(params)
36
36
  # => "/abc/full/full/0/default.jpg"
37
- full_url = File.join(IIIF_BASE_URL, url)
37
+ full_url = File.join(iiif_base_url, url)
38
38
  # => "http://example.edu/prefix/full/full/0/default.jpg"
39
39
  ```
40
40
 
41
- If the constant `IIIF_URL_BASE_URL` is defined then it will form a full url automatically:
41
+ If the base URL is set then it will form a full URL automatically:
42
42
 
43
43
  ```ruby
44
44
  IiifUrl.set_base_url("http://example.edu/prefix")
45
- options = {
45
+ params = {
46
46
  identifier: 'abc',
47
47
  region: 'full',
48
48
  size: 'full',
@@ -50,15 +50,15 @@ options = {
50
50
  quality: 'default',
51
51
  format: 'jpg'
52
52
  }
53
- url = IiifUrl.from_options(options)
53
+ url = IiifUrl.from_params(params)
54
54
  # => "http://example.edu/prefix/abc/full/full/0/default.jpg"
55
55
  ```
56
56
 
57
- You can also pass in the base URL in with the options, which will override any value set for the base URL.
57
+ You can also pass in the base URL in with the params, which will override any value set for the base URL.
58
58
 
59
59
  ```ruby
60
60
  IiifUrl.set_base_url("http://example.edu/prefix")
61
- options = {
61
+ params = {
62
62
  identifier: 'abc',
63
63
  base_url: "http://example.org",
64
64
  region: 'full',
@@ -67,7 +67,7 @@ options = {
67
67
  quality: 'default',
68
68
  format: 'jpg'
69
69
  }
70
- url = IiifUrl.from_options(options)
70
+ url = IiifUrl.from_params(params)
71
71
  # => "http://example.org/abc/full/full/0/default.jpg"
72
72
  ```
73
73
 
@@ -75,7 +75,7 @@ If the base URL is set you can prevent it being used and just return the path po
75
75
 
76
76
  ```ruby
77
77
  IiifUrl.set_base_url("http://example.edu/prefix")
78
- options = {
78
+ params = {
79
79
  identifier: 'abc',
80
80
  base_url: false,
81
81
  region: 'full',
@@ -84,14 +84,14 @@ options = {
84
84
  quality: 'default',
85
85
  format: 'jpg'
86
86
  }
87
- url = IiifUrl.from_options(options)
87
+ url = IiifUrl.from_params(params)
88
88
  # => "/abc/full/full/0/default.jpg"
89
89
  ```
90
90
 
91
91
  A more complicated region and size:
92
92
 
93
93
  ```ruby
94
- options = {
94
+ params = {
95
95
  identifier: 'abc',
96
96
  region: {
97
97
  x: 0,
@@ -104,14 +104,14 @@ options = {
104
104
  quality: 'default',
105
105
  format: 'jpg'
106
106
  }
107
- url = IiifUrl.from_options(options)
107
+ url = IiifUrl.from_params(params)
108
108
  # => "/abc/0,0,1000,1200/300,/0/default.jpg"
109
109
  ```
110
110
 
111
111
  To use a percent region or percent size, you must prefix the keys like this:
112
112
 
113
113
  ```ruby
114
- options = {
114
+ params = {
115
115
  identifier: 'abc',
116
116
  region: {
117
117
  pctx: 10,
@@ -121,28 +121,28 @@ options = {
121
121
  },
122
122
  size: {pct: 50}
123
123
  }
124
- url = IiifUrl.from_options(options)
124
+ url = IiifUrl.from_params(params)
125
125
  # => "/abc/pct:10,10,80,80/pct:50/0/default.jpg"
126
126
  ```
127
127
 
128
128
  If no identifier is passed in, then only the IIIF URL path will be returned:
129
129
 
130
130
  ```ruby
131
- options = {
131
+ params = {
132
132
  size: {pct: 50}
133
133
  }
134
- url = IiifUrl.from_options(options)
134
+ url = IiifUrl.from_params(params)
135
135
  # => "/full/pct:50/0/default.jpg"
136
136
  ```
137
137
 
138
138
  Even if a base_url is given if there is no identifier, then only the IIIF URL path will be returned:
139
139
 
140
140
  ```ruby
141
- options = {
141
+ params = {
142
142
  base_url: "http://example.org/prefix/",
143
143
  size: {pct: 50}
144
144
  }
145
- url = IiifUrl.from_options(options)
145
+ url = IiifUrl.from_params(params)
146
146
  # => "/full/pct:50/0/default.jpg"
147
147
  ```
148
148
 
@@ -161,27 +161,27 @@ You only need to specify values that are different from the defaults. The defaul
161
161
  | format | "jpg" |
162
162
 
163
163
  ```ruby
164
- options = {
164
+ params = {
165
165
  identifier: 'abc',
166
166
  size: {w: 600}
167
167
  }
168
- url = IiifUrl.from_options(options)
168
+ url = IiifUrl.from_params(params)
169
169
  # => "/abc/full/600,/0/default.jpg"
170
170
  ```
171
171
 
172
172
  And without an identifier:
173
173
 
174
174
  ```ruby
175
- options = {
175
+ params = {
176
176
  size: {w: 600}
177
177
  }
178
- url = IiifUrl.from_options(options)
178
+ url = IiifUrl.from_params(params)
179
179
  # => "/full/600,/0/default.jpg"
180
180
  ```
181
181
 
182
182
  ## Chainable
183
183
 
184
- There may be cases where you do not have all of the options you need so you want to pass around a IiifUrl to add more options.
184
+ There may be cases where you do not have all of the params you need so you want to pass around a IiifUrl to add more params.
185
185
 
186
186
  ```ruby
187
187
  url = IiifUrl.new
@@ -191,7 +191,7 @@ url.to_s
191
191
  # => "/100,200,300,300/150,/0/default.png"
192
192
  ```
193
193
 
194
- You can also pass in some initial options and then add on others:
194
+ You can also pass in some initial params and then add on others:
195
195
 
196
196
  ```ruby
197
197
  url = IiifUrl.new({size: {w: 100}})
@@ -209,28 +209,28 @@ IIIF URLs are parsed by segments including: region, size, rotation, quality, and
209
209
  Simple case for region and size parsed into strings:
210
210
 
211
211
  ```ruby
212
- options = IiifUrl.parse("/full/full/0/default.png")
212
+ params = IiifUrl.parse("/full/full/0/default.png")
213
213
  # => {region: "full", size: "full", rotation: {degrees: 0, mirror: false}, quality: 'default', format: 'png'}
214
214
  ```
215
215
 
216
216
  With an identifier:
217
217
 
218
218
  ```ruby
219
- options = IiifUrl.parse("/abc/full/full/0/default.png")
219
+ params = IiifUrl.parse("/abc/full/full/0/default.png")
220
220
  # => {identifier: "abc", region: "full", size: "full", rotation: {degrees: 0, mirror: false}, quality: 'default', format: 'png'}
221
221
  ```
222
222
 
223
223
  Parameterized region and size:
224
224
 
225
225
  ```ruby
226
- options = IiifUrl.parse("/0,100,200,300/75,/0/default.jpg")
226
+ params = IiifUrl.parse("/0,100,200,300/75,/0/default.jpg")
227
227
  # => {identifier: nil, region: {x:0, y:100, w: 200, h: 300}, size: {w: 75, h: nil}, rotation: {degrees: 0, mirror: false}, quality: "default", format: "jpg" }
228
228
  ```
229
229
 
230
230
  Parse a full URL:
231
231
 
232
232
  ```ruby
233
- options = IiifUrl.parse("http://example.org/prefix/abc/0,100,200,300/75,/0/default.jpg")
233
+ params = IiifUrl.parse("http://example.org/prefix/abc/0,100,200,300/75,/0/default.jpg")
234
234
  # => {identifier: abc, region: {x:0, y:100, w: 200, h: 300}, size: {w: 75, h: nil}, rotation: {degrees: 0, mirror: false}, quality: "default", format: "jpg" }
235
235
  ```
236
236
 
@@ -1,3 +1,3 @@
1
1
  class IiifUrl
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/iiif_url.rb CHANGED
@@ -4,57 +4,57 @@ class IiifUrl
4
4
 
5
5
  @@base_url = ""
6
6
 
7
- def initialize(options={})
8
- @options = options
7
+ def initialize(params={})
8
+ @params = params
9
9
  end
10
10
 
11
11
  def identifier(identifier)
12
- @options[:identifier] = identifier
12
+ @params[:identifier] = identifier
13
13
  self
14
14
  end
15
15
 
16
16
  def region(region)
17
- @options[:region] = region
17
+ @params[:region] = region
18
18
  self
19
19
  end
20
20
 
21
21
  def size(size)
22
- @options[:size] = size
22
+ @params[:size] = size
23
23
  self
24
24
  end
25
25
 
26
26
  def rotation(rotation)
27
- @options[:rotation] = rotation
27
+ @params[:rotation] = rotation
28
28
  self
29
29
  end
30
30
 
31
31
  def quality(quality)
32
- @options[:quality] = quality
32
+ @params[:quality] = quality
33
33
  self
34
34
  end
35
35
 
36
36
  def format(format)
37
- @options[:format] = format
37
+ @params[:format] = format
38
38
  self
39
39
  end
40
40
 
41
41
  def to_s
42
- IiifUrl.from_options(@options)
42
+ IiifUrl.from_params(@params)
43
43
  end
44
44
 
45
45
  def self.set_base_url(base_url)
46
46
  @@base_url = base_url
47
47
  end
48
48
 
49
- def self.from_options(options={})
50
- base_url = options[:base_url]
49
+ def self.from_params(params={})
50
+ base_url = params[:base_url]
51
51
  if base_url == false
52
52
  base_url = ''
53
53
  elsif base_url.nil?
54
54
  base_url = @@base_url
55
55
  end
56
56
 
57
- region = options[:region] || "full"
57
+ region = params[:region] || "full"
58
58
  if region.is_a? Hash
59
59
  if region[:x]
60
60
  region = "#{region[:x]},#{region[:y]},#{region[:w]},#{region[:h]}"
@@ -63,7 +63,7 @@ class IiifUrl
63
63
  end
64
64
  end
65
65
 
66
- size = options[:size] || "full"
66
+ size = params[:size] || "full"
67
67
  if size.is_a? Hash
68
68
  if size[:w] || size[:h]
69
69
  size = "#{size[:w]},#{size[:h]}"
@@ -72,7 +72,7 @@ class IiifUrl
72
72
  end
73
73
  end
74
74
 
75
- rotation = options[:rotation] || 0
75
+ rotation = params[:rotation] || 0
76
76
  if rotation.is_a? Hash
77
77
  if rotation[:mirror]
78
78
  rotation = "!#{rotation[:degrees]}"
@@ -81,12 +81,12 @@ class IiifUrl
81
81
  end
82
82
  end
83
83
 
84
- quality = options[:quality] || "default"
85
- format = options[:format] || "jpg"
84
+ quality = params[:quality] || "default"
85
+ format = params[:format] || "jpg"
86
86
 
87
87
  path = "/#{region}/#{size}/#{rotation}/#{quality}.#{format}"
88
- if options[:identifier]
89
- File.join(base_url, options[:identifier], path)
88
+ if params[:identifier]
89
+ File.join(base_url, params[:identifier], path)
90
90
  else
91
91
  path
92
92
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iiif_url
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Ronallo