Class: Wunderlist::List

Inherits:
FilterableList show all
Defined in:
lib/wunderlist/list.rb

Overview

A List is a FilterableList which can be synchronized with an API object

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from FilterableList

#done, #not_done, #not_overdue, #not_priority, #overdue, #priority, #today

Constructor Details

#initialize(name = nil, inbox = nil, api = nil) ⇒ List

Returns a new instance of List.



128
129
130
131
132
# File 'lib/wunderlist/list.rb', line 128

def initialize(name = nil, inbox = nil, api = nil)
  @name = name
  @inbox = inbox
  @api = api
end

Instance Attribute Details

#apiObject

Reference to the associated API object. Necessary for many methods.



126
127
128
# File 'lib/wunderlist/list.rb', line 126

def api
  @api
end

#idObject

ID of the list on the Wunderlist server



110
111
112
# File 'lib/wunderlist/list.rb', line 110

def id
  @id
end

#inboxObject

Value which determines whether this list is a INBOX or or not



118
119
120
# File 'lib/wunderlist/list.rb', line 118

def inbox
  @inbox
end

#nameObject

Name of the list



114
115
116
# File 'lib/wunderlist/list.rb', line 114

def name
  @name
end

#sharedObject

true, if list is shared, otherwise false



122
123
124
# File 'lib/wunderlist/list.rb', line 122

def shared
  @shared
end

Instance Method Details

#create_task(name, date = nil) ⇒ Object

Create task with specified name and date



143
144
145
# File 'lib/wunderlist/list.rb', line 143

def create_task(name, date = nil)
  Wunderlist::Task.new(name, date, self, @api).save
end

#destroy(api = nil) ⇒ Object

Destroy list with api



156
157
158
159
# File 'lib/wunderlist/list.rb', line 156

def destroy(api = nil)
  @api ||= api
  @api.destroy(self)
end

#flushObject

Remove tasks cache



163
164
165
# File 'lib/wunderlist/list.rb', line 163

def flush
  @tasks = nil
end

#save(api = nil) ⇒ Object

Save list with api



149
150
151
152
# File 'lib/wunderlist/list.rb', line 149

def save(api = nil)
  @api ||= api
  @api.save(self)
end

#tasksObject

Get all tasks



136
137
138
139
# File 'lib/wunderlist/list.rb', line 136

def tasks
  @tasks = @api.tasks self if @tasks == nil
  @tasks
end

#to_sObject



167
168
169
170
171
172
173
174
175
176
# File 'lib/wunderlist/list.rb', line 167

def to_s
  lines = []
  lines << "[List]#{inbox ? " [INBOX]" : ""} #{name} - #{tasks.count != 1 ? (tasks.count.to_s + " tasks") : tasks.count.to_s + " task"}"

  tasks.each do |task|
    lines << "  #{task}"
  end

  lines.join "\n"
end