Class: Palaver::Calendar
Instance Method Summary collapse
- #date(d) ⇒ Object
-
#initialize(options = {}) ⇒ Calendar
constructor
A new instance of Calendar.
- #show ⇒ Object
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(={}) super() @default_date = nil .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 |
#show ⇒ Object
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 #@common_options --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 |