Class: TaskList::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/task-list/parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arguments: [], options: {}) ⇒ Parser

Returns a new instance of Parser.



7
8
9
10
11
12
13
14
# File 'lib/task-list/parser.rb', line 7

def initialize(arguments: [], options: {})
  self.search_path = options[:search_path]
  @plain = options[:plain] if options[:plain]
  @type = options[:type].upcase if options[:type]
  @files = fuzzy_find_files queries: arguments
  @tasks = {}
  VALID_TASKS.each { |t| @tasks[t.to_sym] = [] }
end

Instance Attribute Details

#filesObject (readonly)

Returns the value of attribute files.



5
6
7
# File 'lib/task-list/parser.rb', line 5

def files
  @files
end

#search_pathObject

Returns the value of attribute search_path.



5
6
7
# File 'lib/task-list/parser.rb', line 5

def search_path
  @search_path
end

#tasksObject (readonly)

Returns the value of attribute tasks.



5
6
7
# File 'lib/task-list/parser.rb', line 5

def tasks
  @tasks
end

Instance Method Details

#parse!Object

Parse all the collected files to find tasks and populate the tasks hash



26
27
28
29
30
31
32
# File 'lib/task-list/parser.rb', line 26

def parse!
  unless @type.nil? || VALID_TASKS.include?(@type)
    raise TaskList::Exceptions::InvalidTaskTypeError.new type: @type
  end

  @files.each { |f| parsef! file: f }
end

#plain?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/task-list/parser.rb', line 54

def plain?
  !!@plain
end

#print!Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/task-list/parser.rb', line 34

def print!
  @tasks.each do |type, tasks|
    unless tasks.empty?
      puts "#{type}:\n#{'-' * (type.length + 1)}\n"

      tasks.each do |task|
        puts task[:task]

        if self.plain?
          puts "  line #{task[:line_number]} in #{task[:file]}"
        else
          puts "  \e[30m\e[1mline #{task[:line_number]} in #{task[:file]}\e[0m"
        end
      end

      puts
    end
  end
end