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 36 |
# 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{|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} } # 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| if task.parent parent = @tasks[task.parent] if parent # we know the parent parent.children << task task.parent = parent end end end end |
Instance Method Details
#[](uuid) ⇒ Object
direct lookup by uuid
44 45 46 |
# File 'lib/taskwarrior/repository.rb', line 44 def [](uuid) @tasks[uuid] end |
#project(name) ⇒ Object
52 53 54 |
# File 'lib/taskwarrior/repository.rb', line 52 def project(name) @projects[name] if @projects.has_key?(name) end |
#projects ⇒ Object
48 49 50 |
# File 'lib/taskwarrior/repository.rb', line 48 def projects @projects.values end |
#tag(name) ⇒ Object
60 61 62 |
# File 'lib/taskwarrior/repository.rb', line 60 def tag(name) @tags[name] if @tags.has_key?(name) end |
#tags ⇒ Object
56 57 58 |
# File 'lib/taskwarrior/repository.rb', line 56 def @tags.values end |
#tasks ⇒ Object
38 39 40 41 |
# File 'lib/taskwarrior/repository.rb', line 38 def tasks # Do not expose child tasks directly @tasks.values.reject{|t| t.parent} end |