Module: TaskwarriorWeb::CommandBuilder::Base

Included in:
V1, V2
Defined in:
lib/taskwarrior-web/services/builder/base.rb

Constant Summary collapse

TASK_COMMANDS =
{
  :add => 'add',
  :update => TaskwarriorWeb::Config.version.major >= 2 ? ':id mod' : nil,
  :delete => 'rc.confirmation=no :id delete',
  :query => TaskwarriorWeb::Config.version > '1.9.2' ? '_query' : 'export',
  :complete => ':id done',
  :annotate => ':id annotate',
  :denotate => ':id denotate',
  :projects => '_projects',
  :tags => '_tags'
}

Instance Method Summary collapse

Instance Method Details

#buildObject



17
18
19
20
21
22
23
24
# File 'lib/taskwarrior-web/services/builder/base.rb', line 17

def build
  unless @command_string
    task_command
    substitute_parts if @command_string =~ /:id/
  end
  parse_params
  @built = "#{@command_string}#{@params}"
end

#parse_paramsObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/taskwarrior-web/services/builder/base.rb', line 43

def parse_params
  string = ''
  string << %( #{@params.delete(:description).shellescape}) if @params.has_key?(:description)

  if tags = @params.delete(:tags)
    tag_indicator = TaskwarriorWeb::Config.property('tag.indicator') || '+'
    tags.each { |tag| string << %( #{tag_indicator}#{tag.to_s.shellescape}) }
  end

  if tags = @params.delete(:remove_tags)
    tags.each { |tag| string << %( -#{tag.to_s.shellescape}) } 
  end

  @params.each do |attr, value|
    if value.respond_to? :each
      value.each { |val| string << %( #{attr.to_s}:\\"#{val.to_s.shellescape}\\") }
    else
      string << %( #{attr.to_s}:\\"#{value.to_s.shellescape}\\")
    end
  end

  @params = string
  return self
end

#substitute_partsObject



35
36
37
38
39
40
41
# File 'lib/taskwarrior-web/services/builder/base.rb', line 35

def substitute_parts
  if @id
    @command_string.gsub!(':id', "uuid:#{@id.to_s}")
    return self
  end
  raise TaskwarriorWeb::CommandBuilder::MissingTaskIDError
end

#task_commandObject



26
27
28
29
30
31
32
33
# File 'lib/taskwarrior-web/services/builder/base.rb', line 26

def task_command
  if TASK_COMMANDS[@command.to_sym]
    @command_string = TASK_COMMANDS[@command.to_sym].clone
    return self
  else
    raise TaskwarriorWeb::CommandBuilder::InvalidCommandError
  end
end