-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTask.rb
61 lines (58 loc) · 1.41 KB
/
Task.rb
1
2
3
4
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
require "set"
require "date"
class Task
include Comparable
attr_reader :id, :description, :complete, :expiration_date, :group
def initialize(id,description,expiration_date=nil,group="")
@description=description
@id=id
@complete=0 #usamos un integer en vez de un boolean porque integer tiene implementado el metodo <=> (spaceship) y boolean no.
@expiration_date=expiration_date
@group=group
end
def completed
@complete=1
end
def to_s
"%3s["%(@id)+(@complete==1? "x":" ")+"] %10s #{@group} #{@description}" %(date_to_str)
end
def ==(other)
return false unless other.is_a?(Task)
@id==other.id
end
def <=>(other)
return nil unless other.is_a?(Task)
c=@complete<=>other.complete
if(c==0) then
if(@expiration_date==nil && other.expiration_date!=nil) then
c=-1
elsif(other.expiration_date==nil && @expiration_date!=nil) then
c=1
else
c=@id<=>other.id
end
end
c
end
def to_s_without_group
"%3s["%(@id)+(@complete==1? "x":" ")+"] %10s #{@description}" %(date_to_str)
end
private def date_to_str()
str=@expiration_date.to_s
if(@expiration_date==Date.today)
str="today"
elsif(@expiration_date==Date.today-1)
str="yesterday"
elsif(@expiration_date==Date.today+1)
str="tomorrow"
end
str
end
def hash()
[@id].hash
end
def eql?(other)
return nil unless other.is_a(Task)
@id==other.id
end
end