class RworkTrackerCli

Public Class Methods

new(file) click to toggle source
# File lib/rworktracker.rb, line 7
def initialize(file)
  @rw = RworkTracker.new(file)
  @rw.loadYaml
end

Public Instance Methods

addproject() click to toggle source
# File lib/rworktracker.rb, line 32
def addproject
  if ARGV.length > 1 
    @rw.addProject(ARGV[1..-1].join('_'))
    @rw.writeYaml
  else
    warn "you need to provide a project name"
  end
end
help() click to toggle source
# File lib/rworktracker.rb, line 12
def help
  puts "Welcome to RworkTracker: Work Time Tracking Interface"
  puts "Available Commands are:"
  puts "\t pr, projects: list active projects"
  puts "\t add, addproject <projectname>, Add a new project"
  puts "\t start <project name>, Start tracking a project"
  puts "\t stop <project name>, Stop tracking a project"
  puts "\t stats, show total projects stats"
  puts "\t stat <project name>, show total project stats"
end
method_missing(m, *args, &block) click to toggle source
# File lib/rworktracker.rb, line 84
def method_missing(m, *args, &block)  
  if ['pr','add'].include?(m.to_s)
    self.send  self.public_methods.grep(/#{m}/)[0] 
  else
    puts "There's no method called #{m} here"  
    help
  end
end
projects() click to toggle source
# File lib/rworktracker.rb, line 24
def projects
  puts "Active project are:"
  @rw.projects.each do |e| 
    puts e + " - running now" if @rw.started?(e) 
    puts e + " - not running now" if !@rw.started?(e) 
  end
end
start() click to toggle source
# File lib/rworktracker.rb, line 41
def start
  if ARGV.length > 1 
    if @rw.start(ARGV[1..-1].join('_'))
      @rw.writeYaml
    else
      warn "please create the project first"
    end
  else
    warn "you need to provide a project name"
  end
end
stat(pro = ARGV[1..-1].join('_')) click to toggle source
# File lib/rworktracker.rb, line 65
def stat(pro = ARGV[1..-1].join('_'))
  if pro
    tot = @rw.elapsed(pro)
    if tot
      puts "Project #{pro} took #{Time.at(tot).gmtime.strftime('%R:%S')} hours" 
    else
      warn "please provide a valid project"
    end
  else
    warn "you need to provide a project name"
  end
end
stats() click to toggle source
# File lib/rworktracker.rb, line 78
def stats
  @rw.projects.each do |e|
    stat(e)
  end
end
stop() click to toggle source
# File lib/rworktracker.rb, line 53
def stop
  if ARGV.length > 1 
    if @rw.stop(ARGV[1..-1].join('_'))
      @rw.writeYaml
    else
      warn "please create the project first or start it !"
    end
  else
    warn "you need to provide a project name"
  end
end