Top Level Namespace

Defined Under Namespace

Modules: DateUtil Classes: Cycle, NacoConfig, NacoInterface

Instance Method Summary collapse

Instance Method Details



34
35
36
37
38
39
40
# File 'lib/nacofetch.rb', line 34

def print_cycles(cycles)
  puts "\tCycle\tEffective\tEnding"
  puts "-------------------------------------------"
  cycles.each do |cycle|
    puts  "\t#{cycle.number}\t#{cycle.effective.strftime("%b %d %Y")}\t#{cycle.ending.strftime("%b %d %Y")}"
  end
end

#select_cycle(opts) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/nacofetch.rb', line 42

def select_cycle(opts)
  ni = NacoInterface.new
  cycles = ni.cycles

  cycle = nil

  unless opts[:current] or opts[:pending] or opts[:cycle]
    cycle = ni.current_cycle
    if cycles.size > 1
      puts "WARN: no cycle specified, and multiple cycles are available.  Defaulting to current cycle (#{cycle.number})"
    end
  end

  if(opts[:current])
    cycle = ni.current_cycle
  end

  if(opts[:pending])
    cycle = ni.pending_cycle
  end

  if(opts[:cycle])
    cycle = cycles.select { |c| c.number == opts[:cycle] }.first
    if cycle.nil?
      puts "ERROR: cycle #{opts[:cycle]} not found on dTPP.  Available cycles:\n\n"
      print_cycles(cycles)
      exit 0
    end
  end

  if cycle.nil?
    raise "Ended up here with a nil cycle, and I can't handle that"
  end

  status = cycle.status == "PENDING" ? "(effective #{cycle.effective.strftime("%b %d %Y")})" : "(expires #{cycle.ending.strftime("%b %d %Y")})"
  puts "Desired cycle is #{cycle.number} #{status}"

  cycle
end

#string_to_time(time_, format_) ⇒ Object



3
4
5
6
# File 'lib/nacofetch/date_util.rb', line 3

def string_to_time time_, format_
  time = Date._strptime(time_, format_)
  return Time.local(time[:year], time[:mon], time[:mday], time[:hour], time[:min], time[:sec], time[:sec_fraction], time[:zone])
end