Class: TaskWarrior::Repository
- Inherits:
-
Object
- Object
- TaskWarrior::Repository
- Defined in:
- lib/taskwarrior/repository.rb
Instance Method Summary collapse
-
#[](uuid) ⇒ Object
direct lookup by uuid.
-
#initialize(input) ⇒ Repository
constructor
A new instance of Repository.
- #project(name) ⇒ Object
- #projects ⇒ Object
- #tag(name) ⇒ Object
- #tags ⇒ Object
- #tasks ⇒ Object
Constructor Details
#initialize(input) ⇒ Repository
Returns a new instance of Repository.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/taskwarrior/repository.rb', line 5 def initialize(input) @tasks = {} @projects = Hash.new { |hash, key| hash[key] = Project.new(key) } @tags = Hash.new { |hash, key| hash[key] = Tag.new(key) } JSON.parse(input).each do |json| task = TaskWarrior::TaskMapper.map(json) @tasks[task.uuid] = task @projects[task.project].tasks << task if task.project # Create a new Tag object in @tags that is the value for each tag name task..each { |tag_name| @tags[tag_name] << task } end # Replace the uuid of each dependency with the real task @tasks.each_value { |task| task.dependencies.map! { |uuid| @tasks[uuid] } } # Replace the project property of each task with a proper Project object carrying a name and all of the project's tasks @tasks.each_value { |task| task.project = @projects[task.project] if task.project } # Add child tasks to their parent, but keep them in the global index @tasks.each_value do |task| next unless task.parent parent = @tasks[task.parent] if parent # we know the parent parent.children << task task.parent = parent end end end |
Instance Method Details
#[](uuid) ⇒ Object
direct lookup by uuid
43 44 45 |
# File 'lib/taskwarrior/repository.rb', line 43 def [](uuid) @tasks[uuid] end |
#project(name) ⇒ Object
51 52 53 |
# File 'lib/taskwarrior/repository.rb', line 51 def project(name) @projects[name] if @projects.key?(name) end |
#projects ⇒ Object
47 48 49 |
# File 'lib/taskwarrior/repository.rb', line 47 def projects @projects.values end |
#tag(name) ⇒ Object
59 60 61 |
# File 'lib/taskwarrior/repository.rb', line 59 def tag(name) @tags[name] if @tags.key?(name) end |
#tags ⇒ Object
55 56 57 |
# File 'lib/taskwarrior/repository.rb', line 55 def @tags.values end |
#tasks ⇒ Object
37 38 39 40 |
# File 'lib/taskwarrior/repository.rb', line 37 def tasks # Do not expose child tasks directly @tasks.values.reject(&:parent) end |