Class: TheFox::Timr::Command::PopCommand

Inherits:
BasicCommand show all
Includes:
Error, Helper
Defined in:
lib/timr/command/pop_command.rb

Overview

This command pops the Top [Track](TheFox::Timr::Model::Track), makes a duplication of the next Track on the [Stack](TheFox::Timr::Model::Stack), pops the next, and pushes the duplication Track back on the Stack. There are at least 3 Tracks involved.

Man page: [timr-pop(1)](../../../../man/timr-pop.1.html)

### Example

Example Stack before pop:

“‘ Track 1234 stopped Track 2345 stopped Track 3456 running “`

Pop Execution

  1. Make duplication of Track ‘3456` -> new Track `4567`.

Because Track `3456` is the latest Track on the Stack. Sometimes call *Top Track*.
  1. Pop Track ‘3456` from Stack.

  2. Push new Track ‘4567` to Stack.

Example Stack after pop:

“‘ Track 1234 stopped Track 2345 stopped Track 4567 running “`

Constant Summary collapse

MAN_PATH =

Path to man page.

'man/timr-pop.1'

Instance Attribute Summary

Attributes inherited from BasicCommand

#cwd

Instance Method Summary collapse

Methods inherited from BasicCommand

create_command_from_argv, get_command_class_by_name, #shutdown

Constructor Details

#initialize(argv = Array.new) ⇒ PopCommand



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
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/timr/command/pop_command.rb', line 44

def initialize(argv = Array.new)
  super()
  
  @help_opt = false
  
  @start_date_opt = nil
  @start_time_opt = nil
  @end_date_opt = nil
  @end_time_opt = nil
  
  @date_opt = nil
  @time_opt = nil
  
  loop_c = 0 # Limit the loop.
  while loop_c < 1024 && argv.length > 0
    loop_c += 1
    arg = argv.shift
    
    case arg
    when '-h', '--help'
      @help_opt = true
    
    when '--sd', '--start-date'
      @start_date_opt = argv.shift
    when '--st', '--start-time'
      @start_time_opt = argv.shift
    when '--ed', '--end-date'
      @end_date_opt = argv.shift
    when '--et', '--end-time'
      @end_time_opt = argv.shift
    
    when '-d', '--date'
      @date_opt = argv.shift
    when '-t', '--time'
      @time_opt = argv.shift
    
    else
      raise PopCommandError, "Unknown argument '#{arg}'. See 'timr pop --help'."
    end
  end
  
  if @date_opt
    @start_date_opt = @date_opt
    @end_date_opt = @date_opt
  end
  if @time_opt
    @start_time_opt = @time_opt
    @end_time_opt = @time_opt
  end
end

Instance Method Details

#runObject

See BasicCommand#run.



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/timr/command/pop_command.rb', line 96

def run
  if @help_opt
    help
    return
  end
  
  @timr = Timr.new(@cwd)
  
  # Stop
  options = {
    :date => @end_date_opt,
    :time => @end_time_opt,
  }
  
  track = @timr.stop(options)
  unless track
    puts 'No running Track to pop/stop.'
    return
  end
  
  task = track.task
  unless task
    raise TrackError, "Track #{track.id} has no Task."
  end
  
  puts '--- POPED ---'
  puts track.to_compact_str
  puts
  
  # Continue
  options = {
    :date => @start_date_opt,
    :time => @start_time_opt,
  }
  
  track = @timr.continue(options)
  unless track
    puts 'No running Track left on Stack to continue.'
    return
  end
  
  task = track.task
  unless task
    raise TrackError, "Track #{track.id} has no Task."
  end
  
  puts '--- CONTINUED ---'
  puts track.to_compact_str
  puts
  puts @timr.stack
end