Class: TaskList::Parser
- Inherits:
-
Object
- Object
- TaskList::Parser
- Defined in:
- lib/task-list/parser.rb
Instance Attribute Summary collapse
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#search_path ⇒ Object
Returns the value of attribute search_path.
-
#tasks ⇒ Object
readonly
Returns the value of attribute tasks.
Instance Method Summary collapse
-
#initialize(arguments: [], options: {}) ⇒ Parser
constructor
A new instance of Parser.
-
#parse! ⇒ Object
Parse all the collected files to find tasks and populate the tasks hash.
- #plain? ⇒ Boolean
- #print! ⇒ Object
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 = [:search_path] @plain = [:plain] if [:plain] @type = [:type].upcase if [:type] @files = fuzzy_find_files queries: arguments @tasks = {} VALID_TASKS.each { |t| @tasks[t.to_sym] = [] } end |
Instance Attribute Details
#files ⇒ Object (readonly)
Returns the value of attribute files.
5 6 7 |
# File 'lib/task-list/parser.rb', line 5 def files @files end |
#search_path ⇒ Object
Returns the value of attribute search_path.
5 6 7 |
# File 'lib/task-list/parser.rb', line 5 def search_path @search_path end |
#tasks ⇒ Object (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
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 |