Class: Todoly::Task
- Inherits:
-
Object
- Object
- Todoly::Task
- Defined in:
- lib/todoly/task.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #check ⇒ Object
-
#initialize(rest_if, obj) ⇒ Task
constructor
A new instance of Task.
- #save ⇒ Object
- #set_obj(obj) ⇒ Object
- #to_s ⇒ Object
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
#id ⇒ Object (readonly)
Returns the value of attribute id.
26 27 28 |
# File 'lib/todoly/task.rb', line 26 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
26 27 28 |
# File 'lib/todoly/task.rb', line 26 def name @name end |
#raw ⇒ Object (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 |
#check ⇒ Object
42 43 44 45 |
# File 'lib/todoly/task.rb', line 42 def check @raw["Checked"] = true save end |
#save ⇒ Object
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_s ⇒ Object
32 33 34 |
# File 'lib/todoly/task.rb', line 32 def to_s @name end |