class Dens::Mover

Constants

DestinationDoesNotExistError
OriginDoesNotExistError

Attributes

destination[R]
origin[R]

Public Class Methods

move(origin, destination) click to toggle source
# File lib/dens.rb, line 22
def self.move(origin, destination)
  Mover.new(origin, destination).move
end
new(origin, destination = Dir.pwd) click to toggle source
# File lib/dens.rb, line 17
def initialize(origin, destination = Dir.pwd)
  @origin = origin
  @destination = destination
end

Public Instance Methods

move() click to toggle source
# File lib/dens.rb, line 26
def move
  raise OriginDoesNotExistError unless Dir.exists?(origin)
  raise DestinationDoesNotExistError unless Dir.exists?(destination)

  Dir.glob(File.join(origin, "*.png")).each do |drawable_origin|
    drawable_extension = File.extname(drawable_origin)
    drawable_name = File.basename(drawable_origin, drawable_extension)

    partitions = drawable_name.partition("-")
    density = partitions.last
    name = partitions.first

    drawable_destination = File.join(destination, "drawable", name)
    if (!density.empty?)
      directory = File.join(destination, "drawable-#{density}")
      if File.exists?(directory)
        drawable_destination = File.join(directory, name)
      end
    end
    drawable_destination += drawable_extension

    puts "#{drawable_origin} => #{drawable_destination}"
    FileUtils.move(drawable_origin, drawable_destination)
  end
end