Module: Drakkon::Images::FlipFlop
- Defined in:
- lib/drakkon/lib/images/flip_flop.rb
Overview
General Image Index Helper
Class Method Summary collapse
- .images ⇒ Object
- .process(file, horizontal, vertical) ⇒ Object
- .prompt ⇒ Object
- .run!(args = []) ⇒ Object
- .start(horizontal, vertical) ⇒ Object
Class Method Details
.images ⇒ Object
65 66 67 |
# File 'lib/drakkon/lib/images/flip_flop.rb', line 65 def self.images Dir["#{Dir.pwd}/**/*.png"] end |
.process(file, horizontal, vertical) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/drakkon/lib/images/flip_flop.rb', line 57 def self.process(file, horizontal, vertical) image = MiniMagick::Image.open(file) image.flip if vertical image.flop if horizontal image.write file end |
.prompt ⇒ Object
69 70 71 |
# File 'lib/drakkon/lib/images/flip_flop.rb', line 69 def self.prompt TTY::Prompt.new(active_color: :cyan, interrupt: :exit) end |
.run!(args = []) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/drakkon/lib/images/flip_flop.rb', line 5 def self.run!(args = []) # X horizontal = if args.empty? prompt.yes?('Flip Horizontally?') else v = args.shift.downcase %w[yes y].include?(v) end # Y vertical = if args.empty? prompt.yes?('Flip Vertically?') else v = args.shift.downcase %w[yes y].include?(v) end puts <<~HELP Usage [horizontal] [vertical] - Run in the directory you wish to modify the images - Flip/Flop the images via MiniMagick - y / yes / Y / Yes for affirmative args Horizontal: #{horizontal} Vertical: #{vertical} Current Directory; #{Dir.pwd.pastel(:yellow)} Images: HELP images.sort.each do |img| img_s = img.gsub("#{Dir.pwd}/", '').pastel(:yellow) puts " - #{img_s}" end puts exit unless prompt.yes? "#{'Are you sure?'.pastel(:bright_yellow)} Flip/Flop!? #{'(Destructive)'.pastel(:red)}" start(horizontal, vertical) end |