Class: FileSelector

Inherits:
Object
  • Object
show all
Defined in:
lib/file_selector.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFileSelector

Returns a new instance of FileSelector.



9
10
11
12
# File 'lib/file_selector.rb', line 9

def initialize
  @files = Set[]
  @prompt = TTY::Prompt.new
end

Class Method Details

.exploreObject



5
6
7
# File 'lib/file_selector.rb', line 5

def self.explore
  new.explore
end

Instance Method Details

#exploreObject



14
15
16
17
# File 'lib/file_selector.rb', line 14

def explore
  explore_mode
  @files
end

#explore_mode(path = Dir.pwd) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/file_selector.rb', line 19

def explore_mode(path = Dir.pwd)
  system 'clear'
  files = files_in path
  options = ['finish', 'include', File.dirname(path)] + files
  prompt = 'Files and directoies to explore',
  choice = @prompt.select(prompt, options, per_page: 20)
  if choice == 'include'
    include_mode(path)
    explore_mode(path)
  elsif choice != 'finish'
    if File.directory?(choice)
      explore_mode(choice) if File.directory?(choice)
    else
      system "less #{choice}" unless File.directory?(choice)
      explore_mode(path)
    end
  end
end