lib/time_distribution/task.rb in time_distribution-2.1.3 vs lib/time_distribution/task.rb in time_distribution-2.2.0
- old
+ new
@@ -2,19 +2,35 @@
module TimeDistribution
class Task
attr_reader :subject, :time_taken, :desc
+ def self.from_map(map_data)
+ self.new(
+ map_data['subject'].to_sym,
+ map_data['duration'],
+ map_data['description']
+ )
+ end
+
# @param [#to_s] subject The subject on which the task was completed. E.g. A course or project.
# @param [#to_s] time_taken The amount of time taken on the task (Compatible with +ChronicDuration+ parsing, or a range of times that conform to +Chronic+ parsing).
# @param [#to_s] desc The task's description.
def initialize(subject, time_taken, desc)
@subject = subject
@time_taken = SmartDuration.parse(time_taken)
@desc = desc
end
+ def ==(other)
+ (
+ other.subject == @subject &&
+ other.time_taken == @time_taken &&
+ other.desc == @desc
+ )
+ end
+
def to_s() "#{to_headline}: #{to_desc}" end
def to_desc() @desc.strip end
def to_headline
@@ -41,6 +57,6 @@
),
to_hours_s
)
end
end
-end
\ No newline at end of file
+end