Class: Task

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#attributesObject (readonly)

Returns the value of attribute attributes.



2
3
4
# File 'lib/todown/task.rb', line 2

def attributes
  @attributes
end

#finishedObject (readonly)

Returns the value of attribute finished.



2
3
4
# File 'lib/todown/task.rb', line 2

def finished
  @finished
end

#nameObject (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

Parameters:

  • filepath (String)

    filepath of readable markdown file



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