Class: Sheha
- Inherits:
-
Object
show all
- Defined in:
- lib/sheha.rb
Defined Under Namespace
Classes: Event, Helper, InvalidMonthDayError, InvalidMonthError, InvalidWeekDayError, MonthlyEvent, OneTimeEvent, WeeklyEvent, YearlyEvent
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Sheha
Returns a new instance of Sheha.
6
7
8
|
# File 'lib/sheha.rb', line 6
def initialize
@events = Set.new
end
|
Instance Method Details
#add(event) ⇒ Object
10
11
12
|
# File 'lib/sheha.rb', line 10
def add(event)
@events.add event
end
|
#add_monthly_event(month_day) ⇒ Object
39
40
41
|
# File 'lib/sheha.rb', line 39
def add_monthly_event(month_day)
add MonthlyEvent.new(month_day)
end
|
#add_monthly_event_range(from, to) ⇒ Object
57
58
59
|
# File 'lib/sheha.rb', line 57
def add_monthly_event_range(from, to)
add_range MonthlyEvent.new(from), MonthlyEvent.new(to)
end
|
#add_one_time_event(date) ⇒ Object
47
48
49
|
# File 'lib/sheha.rb', line 47
def add_one_time_event(date)
add OneTimeEvent.new(date)
end
|
#add_one_time_event_range(from, to) ⇒ Object
65
66
67
|
# File 'lib/sheha.rb', line 65
def add_one_time_event_range(from, to)
add_range OneTimeEvent.new(from), OneTimeEvent.new(to)
end
|
#add_range(from, to) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/sheha.rb', line 14
def add_range(from, to)
raise "Invalid Range" if not valid_range?(from, to)
(from..to).each do |date|
if block_given?
add yield(date)
else
add date
end
end
end
|
#add_weekly_event(week_day) ⇒ Object
35
36
37
|
# File 'lib/sheha.rb', line 35
def add_weekly_event(week_day)
add WeeklyEvent.new(week_day)
end
|
#add_weekly_event_range(from, to) ⇒ Object
53
54
55
|
# File 'lib/sheha.rb', line 53
def add_weekly_event_range(from, to)
add_range WeeklyEvent.new(from), WeeklyEvent.new(to)
end
|
#add_yearly_event(month, month_day) ⇒ Object
43
44
45
|
# File 'lib/sheha.rb', line 43
def add_yearly_event(month, month_day)
add YearlyEvent.new(month, month_day)
end
|
#add_yearly_event_range(from, to) ⇒ Object
61
62
63
|
# File 'lib/sheha.rb', line 61
def add_yearly_event_range(from, to)
add_range YearlyEvent.new(from[0], from[1]), YearlyEvent.new(to[0], to[1])
end
|
#event?(date) ⇒ Boolean
26
27
28
29
30
31
|
# File 'lib/sheha.rb', line 26
def event?(date)
@events.each do |event|
return true if event.event? date
end
return false
end
|