Class: Task
- Inherits:
-
Object
- Object
- Task
- Defined in:
- lib/todown/task.rb
Overview
Represent a task extracted from markdown file
Instance Attribute Summary collapse
-
#attributes ⇒ Hash
readonly
An hash containing various attributes.
-
#finished ⇒ Boolean
readonly
The status of the task (‘true` for completed, `false` for to do).
-
#name ⇒ String
readonly
The name of the task.
Class Method Summary collapse
-
.from_file(filepath) {|Task| ... } ⇒ Array<Task>
Create many task from given filepath.
Instance Method Summary collapse
-
#initialize(name, finished = false, attributes = {}) ⇒ Task
constructor
Returns a new instance of Task.
Constructor Details
#initialize(name, finished = false, attributes = {}) ⇒ Task
Returns a new instance of Task
32 33 34 35 36 37 38 |
# File 'lib/todown/task.rb', line 32 def initialize(name, finished = false, attributes = {}) @name = name @finished = finished @attributes = attributes parse_attributes! end |
Instance Attribute Details
#attributes ⇒ Hash (readonly)
Returns an hash containing various attributes.
8 9 10 |
# File 'lib/todown/task.rb', line 8 def attributes @attributes end |
#finished ⇒ Boolean (readonly)
Returns The status of the task (‘true` for completed, `false` for to do).
6 7 8 |
# File 'lib/todown/task.rb', line 6 def finished @finished end |
#name ⇒ String (readonly)
Returns The name of the task.
4 5 6 |
# File 'lib/todown/task.rb', line 4 def name @name end |
Class Method Details
.from_file(filepath) {|Task| ... } ⇒ Array<Task>
Create many task from given filepath
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/todown/task.rb', line 15 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 |