Class: Palaver::PathSelect

Inherits:
Base
  • Object
show all
Defined in:
lib/palaver/pathselect.rb

Direct Known Subclasses

DSelect, FSelect

Instance Method Summary collapse

Methods inherited from Base

#height, #text, #width, #with_tempfile

Constructor Details

#initialize(options = {}) ⇒ PathSelect

Returns a new instance of PathSelect.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/palaver/pathselect.rb', line 6

def initialize(options={})
  super(options)
  @path = nil
  
  options.each do |option,value|
    case option
    when :path  then self.path(value)
    end
  end
  
end

Instance Method Details

#path(str) ⇒ Object



18
19
20
# File 'lib/palaver/pathselect.rb', line 18

def path(str)
  @path = str
end

#showObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/palaver/pathselect.rb', line 22

def show
  raise "CAn't open a #{dialog_name} dialog with a path" if not @path
  chosen_file = nil
  with_tempfile do |tfpath|
    cmd = "dialog --#{dialog_name} '#@path' #@height #@width 2> #{tfpath}"
    puts cmd
    success = system cmd
    chosen_file = File.read(tfpath) if success
  end
  return chosen_file
end