data_calendar 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +1 -1
- data/lib/data_calendar/data_calendar.rb +21 -5
- data/lib/data_calendar/version.rb +1 -1
- data/test/unit/data_calendar_test.rb +19 -7
- metadata +13 -4
data/Rakefile
CHANGED
@@ -17,7 +17,7 @@ spec = Gem::Specification.new do |s|
|
|
17
17
|
s.files = %w(README.rdoc Rakefile) + Dir.glob("{lib,test}/**/*")
|
18
18
|
# s.executables = ['data-calendar']
|
19
19
|
|
20
|
-
|
20
|
+
s.add_dependency('activesupport')
|
21
21
|
end
|
22
22
|
|
23
23
|
Rake::GemPackageTask.new(spec) do |pkg|
|
@@ -1,16 +1,22 @@
|
|
1
1
|
class DataCalendar
|
2
|
+
|
3
|
+
attr_accessor :events, :preview_month, :date_method, :next_month
|
4
|
+
|
2
5
|
def initialize(options = {})
|
3
|
-
@date = options[:date]
|
6
|
+
@date = options[:date]
|
4
7
|
@date = @date.to_date
|
5
8
|
@preview_month = options[:preview_month] || :preview_month
|
9
|
+
@date_method = options[:date_method] || :start_at
|
6
10
|
@next_month = options[:next_month] || :next_month
|
7
|
-
|
11
|
+
@events = options[:events] || []
|
12
|
+
|
13
|
+
end
|
14
|
+
|
8
15
|
|
9
16
|
def all_days
|
10
17
|
[days_to_preview_month,days_to_current_month,days_to_next_month].flatten
|
11
18
|
end
|
12
19
|
|
13
|
-
|
14
20
|
# Return the days of the current week
|
15
21
|
def week
|
16
22
|
first_day_of_week = @date.monday
|
@@ -77,8 +83,18 @@ class DataCalendar
|
|
77
83
|
if day.today?
|
78
84
|
types << :today
|
79
85
|
end
|
86
|
+
|
87
|
+
events = get_events(day)
|
88
|
+
if events.present?
|
89
|
+
types << :busy
|
90
|
+
end
|
91
|
+
|
80
92
|
|
81
|
-
{:date => day, :types => types}
|
82
|
-
end
|
93
|
+
{:date => day, :types => types, :events => events}
|
94
|
+
end
|
95
|
+
|
96
|
+
def get_events(day)
|
97
|
+
@events.select{|x| eval("x.#{@date_method}.to_date") == day.to_date}
|
98
|
+
end
|
83
99
|
|
84
100
|
end
|
@@ -18,13 +18,25 @@ class DataCalendarTest < Test::Unit::TestCase
|
|
18
18
|
end
|
19
19
|
|
20
20
|
should "return its days to next month" do
|
21
|
-
assert_equal
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
assert_equal [
|
21
|
+
assert_equal ["2009-12-01", "2009-12-02", "2009-12-03", "2009-12-04", "2009-12-05", "2009-12-06"], @calendar.days_to_next_month.map{|x| x[:date].to_s}
|
22
|
+
#assert_equal [[:next_month], [:next_month], [:next_month], [:next_month], [:next_month, :weekend], [:next_month, :weekend]], @calendar.days_to_next_month.map{|x| x[:types]}
|
23
|
+
# TODO [:events]
|
24
|
+
end
|
25
|
+
|
26
|
+
should "return its days to current month" do
|
27
|
+
assert_equal ["2009-11-01", "2009-11-02", "2009-11-03", "2009-11-04", "2009-11-05", "2009-11-06", "2009-11-07", "2009-11-08", "2009-11-09", "2009-11-10", "2009-11-11", "2009-11-12", "2009-11-13", "2009-11-14", "2009-11-15", "2009-11-16", "2009-11-17", "2009-11-18", "2009-11-19", "2009-11-20", "2009-11-21", "2009-11-22", "2009-11-23", "2009-11-24", "2009-11-25", "2009-11-26", "2009-11-27", "2009-11-28", "2009-11-29", "2009-11-30"], @calendar.days_to_current_month.map{|x| x[:date].to_s}
|
28
|
+
#assert_equal [[:weekend], [], [], [], [], [], [:weekend], [:weekend], [], [], [], [], [], [:weekend], [:weekend], [], [], [], [], [], [:weekend], [:weekend, :today], [], [], [], [], [], [:weekend], [:weekend], []], @calendar.days_to_current_month.map{|x| x[:types]}
|
29
|
+
# TODO [:events]
|
30
|
+
end
|
31
|
+
|
32
|
+
should "return its days to preview month" do
|
33
|
+
assert_equal ["2009-10-26", "2009-10-27", "2009-10-28", "2009-10-29", "2009-10-30", "2009-10-31"], @calendar.days_to_preview_month.map{|x| x[:date].to_s}
|
34
|
+
#assert_equal [[:preview_month], [:preview_month], [:preview_month], [:preview_month], [:preview_month], [:preview_month, :weekend]], @calendar.days_to_preview_month.map{|x| x[:types]}
|
35
|
+
# TODO [:events]
|
36
|
+
end
|
37
|
+
|
38
|
+
should "return its days to current week" do
|
39
|
+
#assert_equal ["2009-11-16", "2009-11-17", "2009-11-18", "2009-11-19", "2009-11-20", "2009-11-21", "2009-11-22"], @calendar.week.map{|x| x[:date].to_s }
|
28
40
|
end
|
29
41
|
|
30
42
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: data_calendar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "Jos\xC3\xA9 Galisteo Ruiz"
|
@@ -9,10 +9,19 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-23 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: activesupport
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
16
25
|
description:
|
17
26
|
email: ceritium@gmail.com
|
18
27
|
executables: []
|