Module: WaxIiif::Utilities::Helpers
- Included in:
- BaseProperties, Builder, ImageVariant
- Defined in:
- lib/wax_iiif/utilities/helpers.rb
Overview
Module Helpers provides helper functions. Which seems logical.
Note that these functions require an @config object to exist on the mixed-in class.
Instance Method Summary collapse
- #escape_yaml(str) ⇒ Object
-
#generate_build_location(id) ⇒ String
Given an id, generate a path on disk for that id, based on the config file.
-
#generate_id(path) ⇒ String
This will generate a valid, escaped URI for an object.
-
#generate_image_location(id) ⇒ String
Given an id and a page number, generate a path on disk for an image The path will be based on the config file.
- #get_data_path(data) ⇒ Object
- #save_to_disk(data) ⇒ Object
Instance Method Details
#escape_yaml(str) ⇒ Object
61 62 63 |
# File 'lib/wax_iiif/utilities/helpers.rb', line 61 def escape_yaml(str) str.gsub(/\A---(.|\n)*?---/, '') end |
#generate_build_location(id) ⇒ String
Given an id, generate a path on disk for that id, based on the config file
34 35 36 |
# File 'lib/wax_iiif/utilities/helpers.rb', line 34 def generate_build_location(id) "#{@config.output_dir}#{@config.prefix}/#{id}" end |
#generate_id(path) ⇒ String
This will generate a valid, escaped URI for an object.
This will prepend the standard path and prefix, and will append .json if enabled.
24 25 26 27 28 |
# File 'lib/wax_iiif/utilities/helpers.rb', line 24 def generate_id(path) val = "#{@config.base_url}#{@config.prefix}/#{path}" val += '.json' if @config.use_extensions val end |
#generate_image_location(id) ⇒ String
Given an id and a page number, generate a path on disk for an image The path will be based on the config file.
43 44 45 |
# File 'lib/wax_iiif/utilities/helpers.rb', line 43 def generate_image_location(id) generate_build_location "#{@config.image_directory_name}/#{id}" end |
#get_data_path(data) ⇒ Object
47 48 49 |
# File 'lib/wax_iiif/utilities/helpers.rb', line 47 def get_data_path(data) data['@id'].gsub(@config.base_url, @config.output_dir) end |
#save_to_disk(data) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/wax_iiif/utilities/helpers.rb', line 51 def save_to_disk(data) path = get_data_path(data) data['@context'] ||= WaxIiif::PRESENTATION_CONTEXT puts "writing #{path}" if @config.verbose? FileUtils.mkdir_p File.dirname(path) File.open(path, 'w') do |file| file.puts JSON.pretty_generate(data) end end |