Class: TaskWarrior::TaskMapper
- Inherits:
-
Object
- Object
- TaskWarrior::TaskMapper
- Defined in:
- lib/taskwarrior/task_mapper.rb
Overview
A DataMapper that makes new Tasks from a JSON representation
Class Method Summary collapse
Class Method Details
.map(json) ⇒ Object
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 |
# File 'lib/taskwarrior/task_mapper.rb', line 9 def map(json) Task.new(json['description']).tap do |t| t.id = json['id'].to_i t.uuid = json['uuid'] t.entry = DateTime.parse(json['entry']) t.status = json['status'].to_sym t.project = json['project'] if json['depends'] t.dependencies = if json['depends'].respond_to?(:split) json['depends'].split(',') else json['depends'] end end t.parent = json['parent'] # Children will be cross-indexed in the repository t.priority = PriorityMapper.map(json['priority']) json['tags']&.each { |tag| t. << tag } json['annotations']&.each { |annotation| t.annotations << AnnotationMapper.map(annotation) } %w[start wait end due].each do |datish| t.send("#{datish}_at=", DateTime.parse(json[datish])) if json[datish] end end end |