class GetToWork::Command::Start

Public Class Methods

new(opts = {}) click to toggle source
Calls superclass method GetToWork::Command::new
# File lib/get_to_work/command/start.rb, line 6
def initialize(opts = {})
  super(opts)
  @pt_id = parse_pt_id(opts[:pt_id])
end

Public Instance Methods

parse_pt_id(pt_id) click to toggle source
# File lib/get_to_work/command/start.rb, line 51
def parse_pt_id(pt_id)
  return nil if pt_id.nil?

  pt_id.delete("#")
  pt_id.match(/\d+$/)[0]
end
prompt_to_use_last_story() click to toggle source
# File lib/get_to_work/command/start.rb, line 31
def prompt_to_use_last_story
  last_story = config_file["last_story"]

  if last_story
    shell.say "\nWould you like to start a timer for your last story?", :green
    shell.say "  ##{last_story[:id.to_s]} ", [:bold, :cyan]
    shell.say "#{last_story[:name.to_s]}", :magenta
    answer = shell.yes? "\n[y/N]", :green

    if answer
      @pt_id = last_story["id"]
    else
      exit(0)
    end
  else
    shell.say "Couldn't find your last started timer. Please specify a story id."
    exit(0)
  end
end
run() click to toggle source
# File lib/get_to_work/command/start.rb, line 11
def run

  if @pt_id.nil?
    prompt_to_use_last_story
  end

  pt = GetToWork::Service::PivotalTracker.new(config_file.data)
  story = pt.story(@pt_id)

  entry = {
    notes: "##{story.id}\n\n#{story.name}\n#{story.url}",
    project_id: harvest_service.project_id,
    task_id: harvest_service.task_id,
  }

  timer = harvest_service.start_timer(entry)
  save_last_timer(timer)
  save_last_story(story)
end
save_last_story(story) click to toggle source
# File lib/get_to_work/command/start.rb, line 58
def save_last_story(story)
  config_file[:last_story.to_s] = {
    "id" => story.id,
    "name" => story.name
  }

  config_file.save
end
save_last_timer(timer) click to toggle source
# File lib/get_to_work/command/start.rb, line 67
def save_last_timer(timer)
  config_file[:last_timer.to_s] = timer.id
  config_file.save
end