Module: Drakkon::Images::List

Defined in:
lib/drakkon/lib/images/list.rb

Overview

General Image Index Helper

Class Method Summary collapse

Class Method Details

.index(args) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/drakkon/lib/images/list.rb', line 24

def self.index(args)
  if args.empty?

    Images.index.keys
  else

    idx = args.flat_map do |filter|
      Images.index.keys.grep(/#{filter}/)
    end

    idx.compact.uniq
  end
end

.listy_list(list) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/drakkon/lib/images/list.rb', line 38

def self.listy_list(list)
  prompt.select('Filter:', filter: true) do |menu|
    menu.choice name: 'exit'
    list.each do |img|
      menu.choice name: img
    end
  end
rescue TTY::Reader::InputInterrupt
  exit 0
end

.promptObject



49
50
51
# File 'lib/drakkon/lib/images/list.rb', line 49

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
# File 'lib/drakkon/lib/images/list.rb', line 5

def self.run!(args = [])
  puts args
  require "#{Dir.pwd}/app/drakkon/image_index"

  loop do
    r = listy_list(index(args))
    break if r == 'exit'

    puts <<~OUTPUT

      #{r.pastel(:bright_blue)}

      **Drakkon::Images.index['#{r}']


    OUTPUT
  end
end