Class: Achoo::UI::MonthChooser

Inherits:
Object
  • Object
show all
Defined in:
lib/achoo/ui/month_chooser.rb

Instance Method Summary collapse

Instance Method Details

#chooseObject



7
8
9
10
11
12
13
# File 'lib/achoo/ui/month_chooser.rb', line 7

def choose
  default = one_month_ago
  period  = Achoo::Term::ask "Period ([#{default}] | YYYYMM)"
  period  = default if !period || period.empty?
  # FIX validate YYYYMM
  period
end

#one_month_agoObject



15
16
17
18
19
20
21
22
23
24
# File 'lib/achoo/ui/month_chooser.rb', line 15

def one_month_ago
  now   = Time.now
  year  = now.year

  # Use -2 + 1 to shift range from 0-11 to 1-12 
  month = (now.month - 2)%12 + 1
  year -= 1 if month > now.month

  sprintf "%d%02d", year, month
end