Class: Dens::Mover
- Inherits:
-
Object
- Object
- Dens::Mover
- Defined in:
- lib/dens.rb
Constant Summary collapse
- OriginDoesNotExistError =
Class.new(RuntimeError)
- DestinationDoesNotExistError =
Class.new(RuntimeError)
Instance Attribute Summary collapse
-
#destination ⇒ Object
readonly
Returns the value of attribute destination.
-
#origin ⇒ Object
readonly
Returns the value of attribute origin.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(origin, destination = Dir.pwd) ⇒ Mover
constructor
A new instance of Mover.
- #move ⇒ Object
Constructor Details
#initialize(origin, destination = Dir.pwd) ⇒ Mover
Returns a new instance of Mover.
17 18 19 20 |
# File 'lib/dens.rb', line 17 def initialize(origin, destination = Dir.pwd) @origin = origin @destination = destination end |
Instance Attribute Details
#destination ⇒ Object (readonly)
Returns the value of attribute destination.
12 13 14 |
# File 'lib/dens.rb', line 12 def destination @destination end |
#origin ⇒ Object (readonly)
Returns the value of attribute origin.
12 13 14 |
# File 'lib/dens.rb', line 12 def origin @origin end |
Class Method Details
Instance Method Details
#move ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# 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 |