Sha256: ab14eabf0f0ecc0dfc65d3eaa9e9e63819ea095ef2f53fe6325edaea5062853b

Contents?: true

Size: 660 Bytes

Versions: 3

Compression:

Stored size: 660 Bytes

Contents

module Riiif
  module FileSystemFileResolver
    mattr_accessor :root, :base_path, :input_types

    self.root = File.expand_path(File.join(File.dirname(__FILE__), '../..'))
    self.base_path = File.join(root, 'spec/samples')
    self.input_types = %W{png jpg tiff jp jp2}


    def self.find(id)
      Riiif::File.new(path(id))
    end

    def self.path(id)
      search = pattern(id)
      Dir.glob(search).first || raise(Errno::ENOENT, search)
    end


    def self.pattern(id)
      raise ArgumentError, "Invalid characters in id `#{id}`" unless /^[\w\-:]+$/.match(id)
      ::File.join(base_path, "#{id}.{#{input_types.join(',')}}")
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
riiif-0.0.6 lib/riiif/file_system_file_resolver.rb
riiif-0.0.5 lib/riiif/file_system_file_resolver.rb
riiif-0.0.4 lib/riiif/file_system_file_resolver.rb