Class: Wunderlist::Task
- Inherits:
-
Object
- Object
- Wunderlist::Task
- Defined in:
- lib/wunderlist/task.rb
Constant Summary collapse
- ATTRIBUTES =
[ :date, :deleted, :done, :done_date, :important, :list_id, :name, :note, :online_id, :position, :push, :push_ts, :user_id, :version, ]
Class Method Summary collapse
Instance Method Summary collapse
- #hash ⇒ Object
-
#initialize(data = {}) ⇒ Task
constructor
A new instance of Task.
- #online_id? ⇒ Boolean
- #sync_data ⇒ Object
Constructor Details
#initialize(data = {}) ⇒ Task
Returns a new instance of Task.
28 29 30 31 32 33 |
# File 'lib/wunderlist/task.rb', line 28 def initialize data = {} data.each do |k,v| self.send("%s=" % k, v) if ATTRIBUTES.include? k end self.version ||= 0 end |
Class Method Details
.from_sync_data(web_data) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/wunderlist/task.rb', line 59 def self.from_sync_data web_data data = Hash.new web_data.each do |k,v| case k.to_s when 'deleted', 'done', 'important', 'shared' data[k.to_sym] = v != '0' when 'done_date' data[k.to_sym] = v == '0' ? nil : Time.at(v.to_i) when 'name', 'note' data[k.to_sym] = v.to_s else data[k.to_sym] = v.to_i end end Wunderlist::Task.new(data) end |
Instance Method Details
#hash ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/wunderlist/task.rb', line 35 def hash data = Hash.new ATTRIBUTES.each do |key| data[key] = self.send(key) end data end |
#online_id? ⇒ Boolean
24 25 26 |
# File 'lib/wunderlist/task.rb', line 24 def online_id? online_id && online_id != 0 end |
#sync_data ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/wunderlist/task.rb', line 43 def sync_data data = self.hash web_data = Hash.new data.each do |k,v| case k when :deleted, :done, :important, :shared web_data[k] = v ? 1 : 0 when :done_date web_data[k] = v ? v.to_i : 0 else web_data[k] = v end end web_data end |