Class: Palaver::Calendar

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

Instance Method Summary collapse

Methods inherited from Base

#height, #text, #width, #with_tempfile

Constructor Details

#initialize(options = {}) ⇒ Calendar

Returns a new instance of Calendar.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/palaver/calendar.rb', line 10

def initialize(options={})
  super(options)
  @default_date = nil

  options.each do |option,value|
    case option
    when :date then self.date(value)
    end
  end
  
end

Instance Method Details

#date(d) ⇒ Object



22
23
24
# File 'lib/palaver/calendar.rb', line 22

def date(d)
  @default_date = d
end

#showObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/palaver/calendar.rb', line 26

def show
  day, month, year =
    if @default_date then [ @default_date.day, @default_date.month, @default_date.year]
    else [ 0, 0, 0 ]
    end
  chosen_date = nil
  with_tempfile do |tfpath|
    cmd = 'dialog --calendar "%s" %d %d %d %d %d 2> %s' % [ @text,
                                                            @height, @width, 
                                                            day, month, year,
                                                            tfpath ]
    success = system cmd
    chosen_date = Date.strptime(File.read(tfpath), "%d/%m/%Y") if success
  end
  return chosen_date
end