Class: WaxIiif::Config

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

Overview

Config provides a data structure for holding the configuration settings for the WaxIiif 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'.freeze
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'.freeze
DEFAULT_OUTPUT_DIRECTORY =

Returns The default path for writing generated image files.

Returns:

  • (String)

    The default path for writing generated image files

'./build'.freeze
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].freeze
DEFAULT_THUMBNAIL_SIZE =

Returns The default thumbnail size in pixels.

Returns:

  • (Number)

    The default thumbnail size in pixels

250
DEFAULT_COLLECTION_LABEL =

Returns The default collection label ~> ‘collection/LABEL.json`.

Returns:

  • (String)

    The default collection label ~> ‘collection/LABEL.json`

'top'.freeze

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):

  • :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

  • :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})


100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/wax_iiif/config.rb', line 100

def initialize(opts = {})
  @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]             || DEFAULT_URL
  @collection_label     = opts[:collection_label]     || DEFAULT_COLLECTION_LABEL
  @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] || ''
  @prefix               = "/#{@prefix}" if @prefix.length.positive? && @prefix[0] != '/'
end

Instance Attribute Details

#base_urlString (readonly)

Returns The protocol, domain, and port used for generating URIs. Defaults to DEFAULT_URL.

Returns:

  • (String)

    The protocol, domain, and port used for generating URIs. Defaults to DEFAULT_URL



26
27
28
# File 'lib/wax_iiif/config.rb', line 26

def base_url
  @base_url
end

#collection_labelString (readonly)

Returns the label for the collection.

Returns:

  • (String)

    the label for the collection



74
75
76
# File 'lib/wax_iiif/config.rb', line 74

def collection_label
  @collection_label
end

#image_directory_nameString (readonly)

Returns The name of the directory/prefix where image files will be located. Defaults to WaxIiif::Config::DEFAULT_IMAGE_DIRECTORY_NAME.

Returns:

  • (String)

    The name of the directory/prefix where image files will be located. Defaults to WaxIiif::Config::DEFAULT_IMAGE_DIRECTORY_NAME



50
51
52
# File 'lib/wax_iiif/config.rb', line 50

def image_directory_name
  @image_directory_name
end

#output_dirString (readonly)

Returns The directory on the local file system where the output files should be saved Defaults to DEFAULT_OUTPUT_DIRECTORY.

Returns:

  • (String)

    The directory on the local file system where the output files should be saved Defaults to DEFAULT_OUTPUT_DIRECTORY



37
38
39
# File 'lib/wax_iiif/config.rb', line 37

def output_dir
  @output_dir
end

#prefixString (readonly)

Defaults to ”

Returns:

  • (String)

    A prefix to be appended between the base URI and the id. Can be blank,and it will automatically prepend a slash if one is not provided.



44
45
46
# File 'lib/wax_iiif/config.rb', line 44

def prefix
  @prefix
end

#thumbnail_sizeNumber (readonly)

Returns The max width in pixels for a thumbnail image.

Returns:

  • (Number)

    The max width in pixels for a thumbnail image



70
71
72
# File 'lib/wax_iiif/config.rb', line 70

def thumbnail_size
  @thumbnail_size
end

#tileArray<Number> (readonly)

Returns An array of tile ratios to be uploaded. Defaults to WaxIiif::Config::DEFAULT_TILE_SCALE_FACTORS.

Returns:

  • (Array<Number>)

    An array of tile ratios to be uploaded. Defaults to WaxIiif::Config::DEFAULT_TILE_SCALE_FACTORS



60
# File 'lib/wax_iiif/config.rb', line 60

attr_reader :tile_scale_factors

#tile_scale_factorsArray<Number> (readonly)

Returns An array of tile ratios to be uploaded. Defaults to WaxIiif::Config::DEFAULT_TILE_SCALE_FACTORS.

Returns:

  • (Array<Number>)

    An array of tile ratios to be uploaded. Defaults to WaxIiif::Config::DEFAULT_TILE_SCALE_FACTORS



60
61
62
# File 'lib/wax_iiif/config.rb', line 60

def tile_scale_factors
  @tile_scale_factors
end

#tile_widthNumber (readonly)

Returns The width (and height) of each individual tile. Defaults to WaxIiif::Config::DEFAULT_TILE_WIDTH.

Returns:

  • (Number)

    The width (and height) of each individual tile. Defaults to WaxIiif::Config::DEFAULT_TILE_WIDTH



55
56
57
# File 'lib/wax_iiif/config.rb', line 55

def tile_width
  @tile_width
end

#use_extensionsBoolean (readonly)

Returns Should generated IDs and files have a .json extension? Defaults to true.

Returns:

  • (Boolean)

    Should generated IDs and files have a .json extension? Defaults to true



31
32
33
# File 'lib/wax_iiif/config.rb', line 31

def use_extensions
  @use_extensions
end

#variantsHash (readonly)

Returns A Hash of key/value pairs. Each key should be the name of a variant, each value the maximum pixel dimension of the longest side. Defaults to {}.

Returns:

  • (Hash)

    A Hash of key/value pairs. Each key should be the name of a variant, each value the maximum pixel dimension of the longest side. Defaults to {}



66
67
68
# File 'lib/wax_iiif/config.rb', line 66

def variants
  @variants
end

#verboseBool (readonly) Also known as: verbose?

Returns Should the program log information to the console?.

Returns:

  • (Bool)

    Should the program log information to the console?



78
79
80
# File 'lib/wax_iiif/config.rb', line 78

def verbose
  @verbose
end

Instance Method Details

#==(other) ⇒ Bool

Compare two configuration files

Parameters:

Returns:

  • (Bool)

    True if they are the same, false otherwise



120
121
122
123
124
125
126
# File 'lib/wax_iiif/config.rb', line 120

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