Class: IiifS3::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/iiif_s3/config.rb

Overview

Config provides a data structure for holding the configuration settings for the IiifS3 class.

Author:

Constant Summary collapse

DEFAULT_URL =

Returns The default URL to append to all IDs.

Returns:

  • (String)

    The default URL to append to all IDs.

"http://0.0.0.0"
DEFAULT_IMAGE_DIRECTORY_NAME =

Returns The name of the subdirectory where generated images live.

Returns:

  • (String)

    The name of the subdirectory where generated images live

"images"
DEFAULT_OUTPUT_DIRECTORY =

Returns The default path for writing generated image files.

Returns:

  • (String)

    The default path for writing generated image files

"./build"
DEFAULT_TILE_WIDTH =

Returns The default tile width/height in pixels.

Returns:

  • (Number)

    The default tile width/height in pixels

512
DEFAULT_TILE_SCALE_FACTORS =

Returns The default tile scaling factors.

Returns:

  • (Array<Number>)

    The default tile scaling factors

[1,2,4,8]
DEFAULT_THUMBNAIL_SIZE =

Returns The default thumbnail size in pixels.

Returns:

  • (Number)

    The default thumbnail size in pixels

250

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Config

Initialize a new configuration option.

Parameters:

  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :upload_to_s3 (Boolean)

    if true, images and metadata will be uploaded to Amazon S3. Defaults to False.

  • :tile_width (Number)

    The width in pixels for generated tiles. Defaults to DEFAULT_TILE_WIDTH

  • :tile_scale_factors (Array<Number>)

    An array of ratios for generated tiles. Defaults to DEFAULT_TILE_SCALE_FACTORS

  • :image_directory_name (String)

    The name of the subdirectory for actual image data. Defaults to DEFAULT_IMAGE_DIRECTORY_NAME

  • :output_dir (String)

    The name of the directory for generated files. image data. Defaults to DEFAULT_OUTPUT_DIRECTORY

  • :base_url (String)

    The base URL for the generated URIs. Defaults to DEFAULT_URL if not auto-uploading to S3 and to the s3 bucket if upload_to_s3 is enabled.

  • :thumbnail_size (Number)

    the size in pixels for the largest side of the thumbnail images. Defaults to DEFAULT_THUMBNAIL_SIZE.

  • :use_extensions (Bool) — default: true

    should files have exensions appended?

  • :verbose (Bool) — default: false

    Should debug information be printed to the console?

  • :prefix (String) — default: ""

    a prefix (read: subdirectory) for the generated URIs.

  • :variants (Hash{String: String})


109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/iiif_s3/config.rb', line 109

def initialize(opts = {})
  @upload_to_s3   = opts[:upload_to_s3] || false
  @s3             = IiifS3::AmazonS3.new if @upload_to_s3
  @tile_width     = opts[:tile_width]                 || DEFAULT_TILE_WIDTH
  @tile_scale_factors = opts[:tile_scale_factors]     || DEFAULT_TILE_SCALE_FACTORS
  @image_directory_name = opts[:image_directory_name] || DEFAULT_IMAGE_DIRECTORY_NAME
  @base_url       = opts[:base_url]                   || ( @upload_to_s3 ? @s3.bucket.url : DEFAULT_URL)
  @use_extensions = opts.fetch(:use_extensions, true) ## true
  @output_dir     = opts[:output_dir]                 || DEFAULT_OUTPUT_DIRECTORY
  @variants       = opts[:variants]                   || {}
  @thumbnail_size = opts[:thumbnail_size]             || DEFAULT_THUMBNAIL_SIZE
  @verbose        = opts.fetch(:verbose, false)       ## false
  @prefix         = opts[:prefix]                     || ""
  if @prefix.length > 0 && @prefix[0] != "/"
    @prefix = "/#{@prefix}" 
  end
end

Instance Attribute Details

#base_urlObject (readonly)

Returns the value of attribute base_url.



27
28
29
# File 'lib/iiif_s3/config.rb', line 27

def base_url
  @base_url
end

#image_directory_nameObject (readonly)

Returns the value of attribute image_directory_name.



51
52
53
# File 'lib/iiif_s3/config.rb', line 51

def image_directory_name
  @image_directory_name
end

#output_dirObject (readonly)

Returns the value of attribute output_dir.



38
39
40
# File 'lib/iiif_s3/config.rb', line 38

def output_dir
  @output_dir
end

#prefixObject (readonly)

Returns the value of attribute prefix.



45
46
47
# File 'lib/iiif_s3/config.rb', line 45

def prefix
  @prefix
end

#s3Object (readonly)

Returns the value of attribute s3.



85
86
87
# File 'lib/iiif_s3/config.rb', line 85

def s3
  @s3
end

#thumbnail_sizeObject (readonly)

Returns the value of attribute thumbnail_size.



76
77
78
# File 'lib/iiif_s3/config.rb', line 76

def thumbnail_size
  @thumbnail_size
end

#tileArray<Number> (readonly)

Defaults to IiifS3::Config::DEFAULT_TILE_SCALE_FACTORS

Returns:

  • (Array<Number>)

    An array of tile ratios to be uploaded.



61
# File 'lib/iiif_s3/config.rb', line 61

attr_reader :tile_scale_factors

#tile_scale_factorsObject (readonly)

Returns the value of attribute tile_scale_factors.



61
62
63
# File 'lib/iiif_s3/config.rb', line 61

def tile_scale_factors
  @tile_scale_factors
end

#tile_widthObject (readonly)

Returns the value of attribute tile_width.



56
57
58
# File 'lib/iiif_s3/config.rb', line 56

def tile_width
  @tile_width
end

#upload_to_s3Object (readonly)

Returns the value of attribute upload_to_s3.



72
73
74
# File 'lib/iiif_s3/config.rb', line 72

def upload_to_s3
  @upload_to_s3
end

#use_extensionsObject (readonly)

Returns the value of attribute use_extensions.



32
33
34
# File 'lib/iiif_s3/config.rb', line 32

def use_extensions
  @use_extensions
end

#variantsObject (readonly)

Returns the value of attribute variants.



67
68
69
# File 'lib/iiif_s3/config.rb', line 67

def variants
  @variants
end

#verboseObject (readonly) Also known as: verbose?

Returns the value of attribute verbose.



80
81
82
# File 'lib/iiif_s3/config.rb', line 80

def verbose
  @verbose
end

Instance Method Details

#==(other_config) ⇒ Bool

Compare two configuration files

Parameters:

Returns:

  • (Bool)

    True if they are the same, false otherwise



134
135
136
137
138
139
140
# File 'lib/iiif_s3/config.rb', line 134

def ==(other_config)
  valid = true
  self.instance_variables.each do |v|
    valid &&= instance_variable_get(v) == other_config.instance_variable_get(v)
  end
  valid
end