Module: GalleryGenerator
- Defined in:
- lib/m1key_gallery_generator/photos_utils.rb,
lib/m1key_gallery_generator/string_utils.rb,
lib/m1key_gallery_generator/console_utils.rb,
lib/m1key_gallery_generator/gallery_config.rb,
lib/m1key_gallery_generator/viewable_photo.rb,
lib/m1key_gallery_generator/gallery_mutators.rb,
lib/m1key_gallery_generator/viewable_gallery.rb,
lib/m1key_gallery_generator/viewable_photo_metadata.rb
Defined Under Namespace
Classes: GalleryConfig, MutableViewableGallery, MutableViewablePhoto, ViewableGallery, ViewablePhoto, ViewablePhotoMetadata
Instance Method Summary collapse
- #add_links_to_descriptions ⇒ Object
- #add_links_to_sources(multi_line_string) ⇒ Object
- #add_tabs_before_every_description_line(how_many_tabs) ⇒ Object
- #add_tabs_before_every_line(multi_line_string, how_many_tabs) ⇒ Object
- #compact(multi_line_string) ⇒ Object
- #create_gallery_image(original_file_name, gallery_slug, photo_id, working_directory) ⇒ Object
- #for_each_photo(&update_function) ⇒ Object
- #get_metadata_for_image_with_file_name_containing(working_directory, file_name_contains) ⇒ Object
- #photos_config_into_viewable_photos(working_directory, gallery_config) ⇒ Object
- #remove_final_empty_line(multi_line_string) ⇒ Object
- #remove_final_empty_line_from_description ⇒ Object
- #tabs(how_many_tabs) ⇒ Object
- #to_photo_id(current_photo_number, photo_id_digits) ⇒ Object
Instance Method Details
#add_links_to_descriptions ⇒ Object
11 12 13 14 15 16 |
# File 'lib/m1key_gallery_generator/gallery_mutators.rb', line 11 def add_links_to_descriptions lambda do |mutable_viewable_content| mutable_viewable_content.description = add_links_to_sources(mutable_viewable_content.description) mutable_viewable_content end end |
#add_links_to_sources(multi_line_string) ⇒ Object
16 17 18 |
# File 'lib/m1key_gallery_generator/string_utils.rb', line 16 def add_links_to_sources(multi_line_string) multi_line_string.gsub(/\[(\d+)\]/, '[<a href="#sources">\1</a>]') end |
#add_tabs_before_every_description_line(how_many_tabs) ⇒ Object
4 5 6 7 8 9 |
# File 'lib/m1key_gallery_generator/gallery_mutators.rb', line 4 def add_tabs_before_every_description_line(how_many_tabs) lambda do |mutable_viewable_content| mutable_viewable_content.description = add_tabs_before_every_line(mutable_viewable_content.description, how_many_tabs) mutable_viewable_content end end |
#add_tabs_before_every_line(multi_line_string, how_many_tabs) ⇒ Object
6 7 8 |
# File 'lib/m1key_gallery_generator/string_utils.rb', line 6 def add_tabs_before_every_line(multi_line_string, how_many_tabs) multi_line_string.each_line.map { |line| tabs(how_many_tabs) + line }.join end |
#compact(multi_line_string) ⇒ Object
2 3 4 |
# File 'lib/m1key_gallery_generator/console_utils.rb', line 2 def compact(multi_line_string) multi_line_string.delete("\t\r\n").squeeze(' ') end |
#create_gallery_image(original_file_name, gallery_slug, photo_id, working_directory) ⇒ Object
49 50 51 |
# File 'lib/m1key_gallery_generator/photos_utils.rb', line 49 def create_gallery_image(original_file_name, gallery_slug, photo_id, working_directory) FileUtils.cp(File.join(working_directory, original_file_name), File.join(working_directory, "#{gallery_slug}_#{photo_id}#{File.extname(original_file_name)}")) end |
#for_each_photo(&update_function) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/m1key_gallery_generator/gallery_mutators.rb', line 25 def for_each_photo(&update_function) lambda do |mutable_viewable_gallery| mutable_viewable_gallery.photos.each do |mutable_viewable_photo| update_function.call(mutable_viewable_photo) end mutable_viewable_gallery end end |
#get_metadata_for_image_with_file_name_containing(working_directory, file_name_contains) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/m1key_gallery_generator/photos_utils.rb', line 34 def (working_directory, file_name_contains) selected_file_name = Dir.entries(working_directory).find { |file_name| file_name.include?(file_name_contains.to_s) } raise "ERROR No matching photo found for #{file_name_contains}." unless selected_file_name exif = EXIFR::JPEG.new(File.join(working_directory, selected_file_name)) photo_width = exif.width photo_height = exif.height photo_iso = exif. photo_focal_length = exif.focal_length.to_f.round.to_s photo_f_number = exif.f_number.to_f photo_exposure_time = exif.exposure_time.to_s ViewablePhotoMetadata.new(selected_file_name, photo_width, photo_height, photo_iso, photo_focal_length, photo_f_number, photo_exposure_time) end |
#photos_config_into_viewable_photos(working_directory, gallery_config) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/m1key_gallery_generator/photos_utils.rb', line 7 def photos_config_into_viewable_photos(working_directory, gallery_config) photos = [] current_photo_number = 0 total_photos_number = gallery_config.total_photos_number photo_id_digits = gallery_config.photo_id_digits puts "There are [#{total_photos_number}] photos total." gallery_config.photos.each do |photo| current_photo_number += 1 photo_id = to_photo_id(current_photo_number, photo_id_digits) photo_title = photo['title'] photo_description = photo['description'] photo_file_name_contains = photo['fileNameContains'] photo_technical_info = photo['technicalInfo'] = (working_directory, photo_file_name_contains) puts "Adding photo with ID [#{photo_id}], title [#{photo_title}], width [#{photo_metadata.width}], height [#{photo_metadata.height}], description [#{compact(photo['description'])}]..." photos.push ViewablePhoto.new(photo_id, photo_title, photo_description, , photo_technical_info) create_gallery_image(.original_file_name, gallery_config.slug, photo_id, working_directory) end photos end |
#remove_final_empty_line(multi_line_string) ⇒ Object
10 11 12 13 14 |
# File 'lib/m1key_gallery_generator/string_utils.rb', line 10 def remove_final_empty_line(multi_line_string) lines = multi_line_string.lines lines[-1] = lines[-1].sub(/[\r\n]$/, '') if lines.any? lines.join end |
#remove_final_empty_line_from_description ⇒ Object
18 19 20 21 22 23 |
# File 'lib/m1key_gallery_generator/gallery_mutators.rb', line 18 def remove_final_empty_line_from_description lambda do |mutable_viewable_content| mutable_viewable_content.description = remove_final_empty_line(mutable_viewable_content.description) mutable_viewable_content end end |
#tabs(how_many_tabs) ⇒ Object
2 3 4 |
# File 'lib/m1key_gallery_generator/string_utils.rb', line 2 def tabs(how_many_tabs) " " * how_many_tabs end |
#to_photo_id(current_photo_number, photo_id_digits) ⇒ Object
30 31 32 |
# File 'lib/m1key_gallery_generator/photos_utils.rb', line 30 def to_photo_id(current_photo_number, photo_id_digits) current_photo_number.to_s.rjust(photo_id_digits, '0') end |