Class: Todoly::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/todoly/task.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rest_if, obj) ⇒ Task

Returns a new instance of Task.



15
16
17
18
# File 'lib/todoly/task.rb', line 15

def initialize(rest_if, obj)
  @rest_if = rest_if
  set_obj(obj)
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



26
27
28
# File 'lib/todoly/task.rb', line 26

def id
  @id
end

#nameObject

Returns the value of attribute name.



26
27
28
# File 'lib/todoly/task.rb', line 26

def name
  @name
end

#rawObject (readonly)

Returns the value of attribute raw.



26
27
28
# File 'lib/todoly/task.rb', line 26

def raw
  @raw
end

Class Method Details

.create(rest_if, name, obj = {}) ⇒ Object



10
11
12
13
# File 'lib/todoly/task.rb', line 10

def self.create(rest_if, name, obj={})
  obj["Content"] = name
  Task.new(rest_if, obj).save
end

.list(rest_if) ⇒ Object



4
5
6
7
8
# File 'lib/todoly/task.rb', line 4

def self.list(rest_if)
  rest_if.items.map do |item|
    self.new(rest_if, item)
  end
end

Instance Method Details

#[](key) ⇒ Object



28
29
30
# File 'lib/todoly/task.rb', line 28

def [](key)
  @raw[key]
end

#checkObject



42
43
44
45
# File 'lib/todoly/task.rb', line 42

def check
  @raw["Checked"] = true
  save
end

#saveObject



47
48
49
50
51
52
53
54
# File 'lib/todoly/task.rb', line 47

def save
  if @id
    @rest_if.update_item_by_id(@id, @raw)
  else
    set_obj @rest_if.create_item(@raw)
  end
  self
end

#set_obj(obj) ⇒ Object



20
21
22
23
24
# File 'lib/todoly/task.rb', line 20

def set_obj(obj)
  @raw = obj
  @id = obj["Id"]
  @name = obj["Content"]
end

#to_sObject



32
33
34
# File 'lib/todoly/task.rb', line 32

def to_s
  @name
end