class RworkTracker

Attributes

wdata[R]
yamlfile[RW]

Public Class Methods

new(yamlfile = nil) click to toggle source
# File lib/rworktracker.rb, line 96
def initialize(yamlfile = nil)
  @yamlfile = yamlfile
  @wdata = Hash.new
  @time = Time.now
end

Public Instance Methods

addProject(pro) click to toggle source
# File lib/rworktracker.rb, line 129
def addProject(pro)
  @wdata[pro] ||= []
end
elapsed(pro) click to toggle source
# File lib/rworktracker.rb, line 161
def elapsed(pro)
  return false unless @wdata[pro]
  total = 0
  @wdata[pro].each  do |e|
    if e['stop']
      total += Time.parse(e['stop']) - Time.parse(e['start'])  
    elsif started?(pro)
      total += Time.now - Time.parse(e['start'])
    end
  end
  return total
end
loadYaml() click to toggle source
# File lib/rworktracker.rb, line 109
def loadYaml
  begin
  f = YAML.load(File.open(@yamlfile))
  rescue
  f = false
  end
  @wdata = ( f == false) ? Hash.new : f
  #check_status
end
projects() click to toggle source
# File lib/rworktracker.rb, line 125
def projects
  @wdata.keys
end
renewTime() click to toggle source
# File lib/rworktracker.rb, line 105
def renewTime
  @time = Time.now
end
start(pro) click to toggle source
# File lib/rworktracker.rb, line 145
def start(pro)
  return false unless @wdata[pro]
  @wdata[pro] << { 'start' => @time.to_s }
  return true
end
started?(pro) click to toggle source
# File lib/rworktracker.rb, line 133
def started?(pro)
  begin
  if @wdata[pro].last['stop'] == nil
    return true
  else
    return false
  end
  rescue 
    return false
  end
end
stop(pro) click to toggle source
# File lib/rworktracker.rb, line 151
def stop(pro)
  return false unless @wdata[pro]
  if @wdata[pro].last.has_key?('start') and !@wdata[pro].last.has_key?('stop') 
    @wdata[pro].last.merge!({ 'stop' => @time.to_s })
    return true
  else
    return false
  end
end
writeYaml() click to toggle source
# File lib/rworktracker.rb, line 119
def writeYaml
  File.open(@yamlfile, File::CREAT|File::TRUNC|File::RDWR) do |f|
    f << YAML::dump(@wdata)
  end
end