Class: CeilingCat::Plugin::Days
- Inherits:
-
Base
- Object
- Base
- CeilingCat::Plugin::Days
show all
- Defined in:
- lib/ceiling_cat/plugins/days.rb
Instance Attribute Summary
Attributes inherited from Base
#event
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#body, #body_without_command, #body_without_nick, #body_without_nick_or_command, #commands, #handle, #initialize, name, #pluralize, public?, #reply, #room, #store, store, #user, #words
Class Method Details
.add_to_holidays(days) ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/ceiling_cat/plugins/days.rb', line 56
def self.add_to_holidays(days)
dates = Array(days).collect do |day|
if is_a_date?(day)
Date.parse(day.to_s)
else
raise NotADateError
end
end
store["holidays"] = (holidays + dates).uniq
end
|
.commands ⇒ Object
6
7
8
9
|
# File 'lib/ceiling_cat/plugins/days.rb', line 6
def self.commands
[{:command => "today", :description => "Find out if there's anything special about today.", :method => "about", :public => true},
{:command => "add holiday", :description => "Add a holiday - '!add holiday 1/19/2011'", :method => "add_to_holidays"}]
end
|
.description ⇒ Object
25
26
27
|
# File 'lib/ceiling_cat/plugins/days.rb', line 25
def self.description
"Holidays and times you shouldn't expect to see us in chat."
end
|
.holidays ⇒ Object
52
53
54
|
# File 'lib/ceiling_cat/plugins/days.rb', line 52
def self.holidays
store["holidays"] ||= []
end
|
.is_a_date?(date_string) ⇒ Boolean
88
89
90
91
92
93
94
|
# File 'lib/ceiling_cat/plugins/days.rb', line 88
def self.is_a_date?(date_string)
begin
return true if Date.parse(date_string.to_s)
rescue ArgumentError => e
return false
end
end
|
.is_a_holiday?(date = Date.today) ⇒ Boolean
80
81
82
83
84
85
86
|
# File 'lib/ceiling_cat/plugins/days.rb', line 80
def self.is_a_holiday?(date=Date.today)
if is_a_date?(date)
holidays.include? Date.parse(date.to_s)
else
raise NotADateError
end
end
|
.is_a_weekend?(date = Date.today) ⇒ Boolean
43
44
45
46
47
48
49
50
|
# File 'lib/ceiling_cat/plugins/days.rb', line 43
def self.is_a_weekend?(date=Date.today)
if is_a_date?(date)
date = Date.parse(date.to_s)
date.wday == 0 || date.wday == 6
else
raise NotADateError
end
end
|
.remove_from_holidays(days) ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/ceiling_cat/plugins/days.rb', line 68
def self.remove_from_holidays(days)
dates = Array(days).collect do |day|
if is_a_date?(day)
Date.parse(day.to_s)
else
raise NotADateError
end
end
store["holidays"] = holidays - dates
end
|
Instance Method Details
#about(date = Date.today) ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/ceiling_cat/plugins/days.rb', line 11
def about(date=Date.today)
begin
if self.class.is_a_holiday?(date)
reply "Today is a holiday!"
elsif self.class.is_a_weekend?(date)
reply "Today is a weekend!"
else
reply "Just a normal day today."
end
rescue NotADateError
reply "Sorry, that's not a valid date."
end
end
|
#add_to_holidays ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/ceiling_cat/plugins/days.rb', line 29
def add_to_holidays
date = body_without_command("add holiday")
if date.empty?
reply "You need to provide a date to add to the holiday list, like 'add holiday 1/19/2011'"
else
begin
self.class.add_to_holidays(body_without_command("add holiday"))
reply "#{date.to_s} has been added to the holiday list."
rescue NotADateError
reply "Sorry, that's not a valid date."
end
end
end
|