Class: Task
- Inherits:
-
Object
- Object
- Task
- Defined in:
- lib/todown/task.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#finished ⇒ Object
readonly
Returns the value of attribute finished.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
-
.from_file(filepath) ⇒ Object
Create many task from given filepath.
Instance Method Summary collapse
-
#initialize(name, finished = false, attributes = {}) ⇒ Task
constructor
A new instance of Task.
Constructor Details
#initialize(name, finished = false, attributes = {}) ⇒ Task
Returns a new instance of Task.
18 19 20 21 22 23 24 |
# File 'lib/todown/task.rb', line 18 def initialize(name, finished = false, attributes = {}) @name = name @finished = finished @attributes = attributes parse_attributes! end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
2 3 4 |
# File 'lib/todown/task.rb', line 2 def attributes @attributes end |
#finished ⇒ Object (readonly)
Returns the value of attribute finished.
2 3 4 |
# File 'lib/todown/task.rb', line 2 def finished @finished end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
2 3 4 |
# File 'lib/todown/task.rb', line 2 def name @name end |
Class Method Details
.from_file(filepath) ⇒ Object
Create many task from given filepath
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/todown/task.rb', line 6 def self.from_file filepath tasks = [] File.read(filepath).scan(/- \[( |X|x)\] (.+)/).each do |data| task = Task.new data[1], (data[0] != ' ') tasks << task yield task if block_given? end return tasks end |