Class: Todoist::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/todoist/project.rb

Overview

Project

A todoist project.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, parameters = {}) ⇒ Todoist::Project

Create a new project

Creates a new Todoist project.

Parameters:

  • name (String)

    The name of the project

  • parameters (Hash) (defaults to: {})

    The other parameters which make up the project.



45
46
47
48
49
50
51
52
53
54
# File 'lib/todoist/project.rb', line 45

def initialize(name, parameters={})
  @name       = name
  @id         = parameters['id']
  @user_id    = parameters['user_id']
  @color      = parameters['color']
  @collapsed  = parameters['collapsed']
  @order      = parameters['item_order']
  @count      = parameters['cache_count']
  @indent     = parameters['indent']
end

Instance Attribute Details

#collapsedObject (readonly)

Returns the value of attribute collapsed.



7
8
9
# File 'lib/todoist/project.rb', line 7

def collapsed
  @collapsed
end

#colorObject (readonly)

Returns the value of attribute color.



7
8
9
# File 'lib/todoist/project.rb', line 7

def color
  @color
end

#idObject (readonly)

Returns the value of attribute id.



7
8
9
# File 'lib/todoist/project.rb', line 7

def id
  @id
end

#indentObject (readonly)

Returns the value of attribute indent.



7
8
9
# File 'lib/todoist/project.rb', line 7

def indent
  @indent
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/todoist/project.rb', line 7

def name
  @name
end

#orderObject (readonly)

Returns the value of attribute order.



7
8
9
# File 'lib/todoist/project.rb', line 7

def order
  @order
end

#user_idObject (readonly)

Returns the value of attribute user_id.



7
8
9
# File 'lib/todoist/project.rb', line 7

def user_id
  @user_id
end

Class Method Details

.allArray

Get all projects

Fetches all the user’s todist projects.

Returns:

  • (Array)

    An Array of todoist project instances.



15
16
17
18
19
20
21
# File 'lib/todoist/project.rb', line 15

def self.all
  projects = []
  Base.get('/getProjects').each do |project|
    projects << new_from_api_request(project)
  end
  projects
end

.get(id) ⇒ Todoist::Project

Get a project

Fetches a todoist project

Parameters:

Returns:



31
32
33
# File 'lib/todoist/project.rb', line 31

def self.get(id)
  new_from_api_request(get_project(id))
end

Instance Method Details

#add_task(content, opts = {}) ⇒ Todoist::Task

Add task

Adds a task to the project.

Parameters:

  • content (String)

    The content of the new task

  • opts (Hash) (defaults to: {})

    The options for the new task

Returns:



110
111
112
# File 'lib/todoist/project.rb', line 110

def add_task(content, opts={})
  Task.new(content, self, opts).save
end

#collapsed?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/todoist/project.rb', line 69

def collapsed?
  (collapsed == 1) ? true : false
end

#completed_tasksArray

Get completed tasks for the project

Returns:

  • (Array)

    An Array of completed Todoist::Tasks



96
97
98
# File 'lib/todoist/project.rb', line 96

def completed_tasks
  Task.completed(self)
end

#inspectObject



65
66
67
# File 'lib/todoist/project.rb', line 65

def inspect
  "<Project:#{name}:#{id}:#{task_count}:user_id=#{user_id} color='#{color}' collapsed=#{collapsed?} order=#{order} indent=#{indent}>"
end

#task_countInteger

The task count

The number of tasks a project has, according to its cache_count when it was fetched

Returns:

  • (Integer)

    The number of tasks this project has



80
81
82
# File 'lib/todoist/project.rb', line 80

def task_count
  @count
end

#tasksArray

Get uncompleted tasks for the project

Returns:

  • (Array)

    An Array of Todoist::Tasks



88
89
90
# File 'lib/todoist/project.rb', line 88

def tasks
  Task.uncompleted(self)
end

#to_iObject



61
62
63
# File 'lib/todoist/project.rb', line 61

def to_i
  id
end

#to_sObject



57
58
59
# File 'lib/todoist/project.rb', line 57

def to_s
  "#{name}"
end