Class: Woro::TaskList

Inherits:
Object
  • Object
show all
Defined in:
lib/woro/task_list.rb

Overview

Generates the list of all tasks for printout to console.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ TaskList

Returns a new instance of TaskList.



10
11
12
13
# File 'lib/woro/task_list.rb', line 10

def initialize(config)
  @config = config
  @list = []
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



8
9
10
# File 'lib/woro/task_list.rb', line 8

def config
  @config
end

#listObject (readonly)

Returns the value of attribute list.



8
9
10
# File 'lib/woro/task_list.rb', line 8

def list
  @list
end

Class Method Details

.extract_description(task_content) ⇒ Object

Extract description from gist’s data content string.

String

description string

Parameters:

  • data (Hash)

    gist data hash



39
40
41
42
43
# File 'lib/woro/task_list.rb', line 39

def self.extract_description(task_content)
  # regex from http://stackoverflow.com/questions/171480/regex-grabbing-values-between-quotation-marks
  match = task_content.match(/desc (["'])((?:(?!\1)[^\\]|(?:\\\\)*\\[^\\])*)\1/)
  match && match[2] || 'No description'
end

Instance Method Details

#fillObject

Fill task list by loading tasks from the configured adapters and locally.

Returns:

  • (Object)

    task_list



23
24
25
26
27
# File 'lib/woro/task_list.rb', line 23

def fill
  fill_list_from_adapters
  fill_list_from_local
  self
end

Print the current task list to console.



30
31
32
33
34
# File 'lib/woro/task_list.rb', line 30

def print
  list.each do |entry|
    entry.headline ? print_headline(entry) : print_task_description(entry)
  end
end

#widthinteger

Determine the max count of characters for all task names.

Returns:

  • (integer)

    count of characters



17
18
19
# File 'lib/woro/task_list.rb', line 17

def width
  @width ||= list.map { |t| t.name_with_args ? t.name_with_args.length : 0 }.max || 10
end