lib/iiif_url.rb in iiif_url-0.0.4 vs lib/iiif_url.rb in iiif_url-0.0.5

- old
+ new

@@ -100,32 +100,44 @@ url_parts = url.split('/') quality_format = url_parts.pop quality, format = quality_format.split('.') rotation_string = url_parts.pop - rotation = if rotation_string.include?('!') - degrees = rotation_string.sub('!', '') - {degrees: degrees.to_i, mirror: true} + rotation = {} + rotation[:mirror] = if rotation_string.include?('!') + rotation_string.sub!('!', '') + true else - {degrees: rotation_string.to_i, mirror: false} + false end + rotation[:degrees] = if is_number?(rotation_string) + rotation_string.to_i + else + rotation_string + end size_string = url_parts.pop - size = if size_string.include?(',') + size = {} + if size_string =~ /^!\d+,\d+/ + size[:confined] = true + size_string.gsub!('!', '') + end + if size_string.include?(',') w, h = size_string.split(',') w = if w.empty? nil else w.to_i end h = h.to_i if !h.nil? - {w: w, h: h} + size[:w] = w + size[:h] = h elsif size_string.include?('pct') - pct, size = size_string.split(':') - {pct: size.to_f} + pct, pct_size = size_string.split(':') + size[:pct] = pct_size.to_f else - size_string + size = size_string end region_string = url_parts.pop region = if region_string.include?(',') if region_string.include?('pct') @@ -149,7 +161,13 @@ size: size, rotation: rotation, quality: quality, format: format } + end + + private + + def self.is_number?(string) + true if Float(string) rescue false end end