class MobileExport::Android
Constants
- IMAGE_EXTENSIONS
- SUFFIX_FOLDER
Attributes
current_directory[R]
Public Class Methods
new(current_directory = Pathname.getwd)
click to toggle source
# File lib/mobile_export/android.rb, line 6 def initialize(current_directory = Pathname.getwd) @current_directory = Pathname(current_directory) end
Public Instance Methods
run()
click to toggle source
# File lib/mobile_export/android.rb, line 10 def run create_directories! move_images! end
Private Instance Methods
all_image_files()
click to toggle source
# File lib/mobile_export/android.rb, line 50 def all_image_files @_all_image_files = Dir[image_patterns_for_glob] end
create_directories!()
click to toggle source
# File lib/mobile_export/android.rb, line 32 def create_directories! SUFFIX_FOLDER.values.each do |directory| path = current_directory.join directory FileUtils.mkdir_p(path) if !path.directory? end end
image_patterns()
click to toggle source
# File lib/mobile_export/android.rb, line 46 def image_patterns @_image_patterns ||= Regexp.compile(IMAGE_EXTENSIONS.join("|".freeze)) end
image_patterns_for_glob()
click to toggle source
# File lib/mobile_export/android.rb, line 40 def image_patterns_for_glob @_image_patterns_for_glob ||= begin current_directory.join("*.{#{IMAGE_EXTENSIONS.join(",".freeze)}}").to_s end end
move_images!()
click to toggle source
# File lib/mobile_export/android.rb, line 54 def move_images! SUFFIX_FOLDER.each do |suffix, folder| destination = current_directory.join(folder) files_with_suffix = all_image_files.select do |file| file =~ /_#{suffix}\.(#{image_patterns})$/ end files_with_suffix.each do |file| matched = Pathname(file).basename.to_s.match( /(?<filename>.*)_(?<suffix>(#{suffix}))(?<extension>\..*)$/ ) old_path = file new_path = destination.join(matched[:filename] + matched[:extension]).to_s puts "Move #{old_path} to #{new_path}." FileUtils.mv old_path, new_path end end end