Class: Redpomo::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/redpomo/task.rb

Constant Summary collapse

ISSUES_REGEXP =
/(?:\s+|^)#[0-9]+/

Instance Method Summary collapse

Constructor Details

#initialize(list, text) ⇒ Task

Returns a new instance of Task.



24
25
26
27
# File 'lib/redpomo/task.rb', line 24

def initialize(list, text)
  @task = Todo::Task.new(text)
  @list = list
end

Instance Method Details

#add!Object



59
60
61
# File 'lib/redpomo/task.rb', line 59

def add!
  TaskList.add!(self)
end

#close_issue!(message = nil) ⇒ Object



51
52
53
# File 'lib/redpomo/task.rb', line 51

def close_issue!(message = nil)
  tracker.close_issue!(issue, message)
end

#contextObject



29
30
31
32
33
# File 'lib/redpomo/task.rb', line 29

def context
  @task.contexts.map do |context|
    context.gsub /^@/, ''
  end.first
end

#done!Object



55
56
57
# File 'lib/redpomo/task.rb', line 55

def done!
  @list.remove!(self)
end

#issueObject



41
42
43
44
45
# File 'lib/redpomo/task.rb', line 41

def issue
  orig.scan(ISSUES_REGEXP).map(&:strip).map do |issue|
    issue.gsub(/^#/, '').to_i
  end.first
end

#open_in_browser!Object



63
64
65
66
# File 'lib/redpomo/task.rb', line 63

def open_in_browser!
  require 'launchy'
  Launchy.open(url)
end

#projectObject



35
36
37
38
39
# File 'lib/redpomo/task.rb', line 35

def project
  @task.projects.map do |context|
    context.gsub /^\+/, ''
  end.first
end

#start_pomodoro!Object



68
69
70
71
72
73
74
# File 'lib/redpomo/task.rb', line 68

def start_pomodoro!
  require 'applescript'
  command = 'tell application "Pomodoro" to start "'
  command << orig
  command << '"'
  AppleScript.execute(command)
end

#textObject



47
48
49
# File 'lib/redpomo/task.rb', line 47

def text
  @task.text.gsub(ISSUES_REGEXP, '').strip
end

#to_issueObject



91
92
93
94
95
96
97
98
# File 'lib/redpomo/task.rb', line 91

def to_issue
  issue = Issue.new(tracker)
  issue.subject = text
  issue.project_id = project
  issue.due_date = date
  issue.priority_id = tracker.issue_priority_id(priority) if tracker.present?
  issue
end

#trackerObject



87
88
89
# File 'lib/redpomo/task.rb', line 87

def tracker
  Tracker.find(context) if context.present?
end

#urlObject



76
77
78
79
80
81
82
83
84
85
# File 'lib/redpomo/task.rb', line 76

def url
  return nil unless tracker.present?
  if issue.present?
    "#{tracker.base_url}/issues/#{issue}"
  elsif project.present?
    "#{tracker.base_url}/projects/#{project}"
  else
    "#{tracker.base_url}/projects/#{tracker.default_project}"
  end
end