Class: Task

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

Overview

Represent a task extracted from markdown file

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

Parameters:

  • name (String)
  • finished (Boolean) (defaults to: false)
  • attributes (Hash) (defaults to: {})

    an hash containing various attributes



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

#attributesHash (readonly)

Returns an hash containing various attributes.

Returns:

  • (Hash)

    an hash containing various attributes



8
9
10
# File 'lib/todown/task.rb', line 8

def attributes
  @attributes
end

#finishedBoolean (readonly)

Returns The status of the task (‘true` for completed, `false` for to do).

Returns:

  • (Boolean)

    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

#nameString (readonly)

Returns The name of the task.

Returns:

  • (String)

    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

Parameters:

  • filepath (String)

    filepath of readable markdown file

Yields:

Returns:



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