Class: PTJ::Task

Inherits:
Object
  • Object
show all
Includes:
DataMapper::Resource
Defined in:
lib/ptj/model/tasks.rb

Constant Summary collapse

REQUIRED =
[:description, :is_done]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse_json(body) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/ptj/model/tasks.rb', line 26

def self.parse_json(body)
  json = JSON.parse(body)
  ret = { :description => json['description'], :is_done => json['isDone'] }
  return nil if REQUIRED.find { |r| ret[r].nil? }
 
  ret 
end

Instance Method Details

#to_json(*a) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/ptj/model/tasks.rb', line 16

def to_json(*a)
  { 
    'guid'        => self.url, 
    'description' => self.description,
    'isDone'      => self.is_done 
  }.to_json(*a)
end

#urlObject



12
13
14
# File 'lib/ptj/model/tasks.rb', line 12

def url
  "/tasks/#{self.id}"
end