data-calendar 0.1.0
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/README.rdoc +86 -0
- data/Rakefile +57 -0
- data/lib/data_calendar.rb +5 -0
- data/lib/data_calendar/data_calendar.rb +71 -0
- data/lib/data_calendar/version.rb +13 -0
- data/test/test_helper.rb +7 -0
- data/test/unit/data_calendar_test.rb +33 -0
- metadata +62 -0
data/README.rdoc
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
= DataCalendar
|
2
|
+
|
3
|
+
== Description
|
4
|
+
|
5
|
+
Generates the data needed to represent a given schedule a calendar.
|
6
|
+
|
7
|
+
== Installation
|
8
|
+
|
9
|
+
sudo gem install data-calendar
|
10
|
+
|
11
|
+
== Usage
|
12
|
+
|
13
|
+
require 'data_calendar'
|
14
|
+
|
15
|
+
dc = DataCalendar.new(:date => Time.now -1.year)
|
16
|
+
|
17
|
+
pp dc.all_days #=>
|
18
|
+
|
19
|
+
[{:types=>[:preview_month], :date=>Mon, 26 Oct 2009},
|
20
|
+
{:types=>[:preview_month], :date=>Tue, 27 Oct 2009},
|
21
|
+
{:types=>[:preview_month], :date=>Wed, 28 Oct 2009},
|
22
|
+
{:types=>[:preview_month], :date=>Thu, 29 Oct 2009},
|
23
|
+
{:types=>[:preview_month], :date=>Fri, 30 Oct 2009},
|
24
|
+
{:types=>[:preview_month, :weekend], :date=>Sat, 31 Oct 2009},
|
25
|
+
{:types=>[:weekend], :date=>Sun, 01 Nov 2009},
|
26
|
+
{:types=>[], :date=>Mon, 02 Nov 2009},
|
27
|
+
{:types=>[], :date=>Tue, 03 Nov 2009},
|
28
|
+
{:types=>[], :date=>Wed, 04 Nov 2009},
|
29
|
+
{:types=>[], :date=>Thu, 05 Nov 2009},
|
30
|
+
{:types=>[], :date=>Fri, 06 Nov 2009},
|
31
|
+
{:types=>[:weekend], :date=>Sat, 07 Nov 2009},
|
32
|
+
{:types=>[:weekend], :date=>Sun, 08 Nov 2009},
|
33
|
+
{:types=>[], :date=>Mon, 09 Nov 2009},
|
34
|
+
{:types=>[], :date=>Tue, 10 Nov 2009},
|
35
|
+
{:types=>[], :date=>Wed, 11 Nov 2009},
|
36
|
+
{:types=>[], :date=>Thu, 12 Nov 2009},
|
37
|
+
{:types=>[:today], :date=>Fri, 13 Nov 2009},
|
38
|
+
{:types=>[:weekend], :date=>Sat, 14 Nov 2009},
|
39
|
+
{:types=>[:weekend], :date=>Sun, 15 Nov 2009},
|
40
|
+
{:types=>[], :date=>Mon, 16 Nov 2009},
|
41
|
+
{:types=>[], :date=>Tue, 17 Nov 2009},
|
42
|
+
{:types=>[], :date=>Wed, 18 Nov 2009},
|
43
|
+
{:types=>[], :date=>Thu, 19 Nov 2009},
|
44
|
+
{:types=>[], :date=>Fri, 20 Nov 2009},
|
45
|
+
{:types=>[:weekend], :date=>Sat, 21 Nov 2009},
|
46
|
+
{:types=>[:weekend], :date=>Sun, 22 Nov 2009},
|
47
|
+
{:types=>[], :date=>Mon, 23 Nov 2009},
|
48
|
+
{:types=>[], :date=>Tue, 24 Nov 2009},
|
49
|
+
{:types=>[], :date=>Wed, 25 Nov 2009},
|
50
|
+
{:types=>[], :date=>Thu, 26 Nov 2009},
|
51
|
+
{:types=>[], :date=>Fri, 27 Nov 2009},
|
52
|
+
{:types=>[:weekend], :date=>Sat, 28 Nov 2009},
|
53
|
+
{:types=>[:weekend], :date=>Sun, 29 Nov 2009},
|
54
|
+
{:types=>[], :date=>Mon, 30 Nov 2009},
|
55
|
+
{:types=>[:next_month], :date=>Tue, 01 Dec 2009},
|
56
|
+
{:types=>[:next_month], :date=>Wed, 02 Dec 2009},
|
57
|
+
{:types=>[:next_month], :date=>Thu, 03 Dec 2009},
|
58
|
+
{:types=>[:next_month], :date=>Fri, 04 Dec 2009},
|
59
|
+
{:types=>[:next_month, :weekend], :date=>Sat, 05 Dec 2009},
|
60
|
+
{:types=>[:next_month, :weekend], :date=>Sun, 06 Dec 2009}]
|
61
|
+
|
62
|
+
|
63
|
+
== License
|
64
|
+
|
65
|
+
Copyright (c) 2009 José Galisteo Ruiz
|
66
|
+
|
67
|
+
Permission is hereby granted, free of charge, to any person
|
68
|
+
obtaining a copy of this software and associated documentation
|
69
|
+
files (the "Software"), to deal in the Software without
|
70
|
+
restriction, including without limitation the rights to use,
|
71
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
72
|
+
copies of the Software, and to permit persons to whom the
|
73
|
+
Software is furnished to do so, subject to the following
|
74
|
+
conditions:
|
75
|
+
|
76
|
+
The above copyright notice and this permission notice shall be
|
77
|
+
included in all copies or substantial portions of the Software.
|
78
|
+
|
79
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
80
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
81
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
82
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
83
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
84
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
85
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
86
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake/gempackagetask'
|
3
|
+
require 'rake/testtask'
|
4
|
+
|
5
|
+
require 'lib/data_calendar/version'
|
6
|
+
|
7
|
+
spec = Gem::Specification.new do |s|
|
8
|
+
s.name = 'data-calendar'
|
9
|
+
s.version = DataCalendar::Version.to_s
|
10
|
+
s.has_rdoc = true
|
11
|
+
s.extra_rdoc_files = %w(README.rdoc)
|
12
|
+
s.rdoc_options = %w(--main README.rdoc)
|
13
|
+
s.summary = "Generates the data needed to represent a given schedule a calendar."
|
14
|
+
s.author = 'José Galisteo Ruiz'
|
15
|
+
s.email = 'ceritium@gmail.com'
|
16
|
+
s.homepage = 'http://jose.gr'
|
17
|
+
s.files = %w(README.rdoc Rakefile) + Dir.glob("{lib,test}/**/*")
|
18
|
+
# s.executables = ['data-calendar']
|
19
|
+
|
20
|
+
# s.add_dependency('gem_name', '~> 0.0.1')
|
21
|
+
end
|
22
|
+
|
23
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
24
|
+
pkg.gem_spec = spec
|
25
|
+
end
|
26
|
+
|
27
|
+
Rake::TestTask.new do |t|
|
28
|
+
t.libs << 'test'
|
29
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
30
|
+
t.verbose = true
|
31
|
+
end
|
32
|
+
|
33
|
+
begin
|
34
|
+
require 'rcov/rcovtask'
|
35
|
+
|
36
|
+
Rcov::RcovTask.new(:coverage) do |t|
|
37
|
+
t.libs = ['test']
|
38
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
39
|
+
t.verbose = true
|
40
|
+
t.rcov_opts = ['--text-report', "-x #{Gem.path}", '-x /Library/Ruby', '-x /usr/lib/ruby']
|
41
|
+
end
|
42
|
+
|
43
|
+
task :default => :coverage
|
44
|
+
|
45
|
+
rescue LoadError
|
46
|
+
warn "\n**** Install rcov (sudo gem install relevance-rcov) to get coverage stats ****\n"
|
47
|
+
task :default => :test
|
48
|
+
end
|
49
|
+
|
50
|
+
desc 'Generate the gemspec for the Gem (useful when serving from Github)'
|
51
|
+
task :gemspec do
|
52
|
+
file = File.dirname(__FILE__) + "/#{spec.name}.gemspec"
|
53
|
+
File.open(file, 'w') {|f| f << spec.to_ruby }
|
54
|
+
puts "Created gemspec: #{file}"
|
55
|
+
end
|
56
|
+
|
57
|
+
task :github => :gemspec
|
@@ -0,0 +1,71 @@
|
|
1
|
+
class DataCalendar
|
2
|
+
def initialize(options = {})
|
3
|
+
@date = options[:date] || Time.now
|
4
|
+
@date = @date.to_date
|
5
|
+
@preview_month = options[:preview_month] || :preview_month
|
6
|
+
@next_month = options[:next_month] || :next_month
|
7
|
+
end
|
8
|
+
|
9
|
+
def all_days
|
10
|
+
[days_to_preview_month,days_to_current_month,days_to_next_month].flatten
|
11
|
+
end
|
12
|
+
|
13
|
+
def days_to_preview_month
|
14
|
+
fill_days = first_day_of_month.wday
|
15
|
+
fill_days = 7 if fill_days == 0
|
16
|
+
fill_days -= 1
|
17
|
+
first_day_of_month - fill_days.days
|
18
|
+
|
19
|
+
days = []
|
20
|
+
fill_days.times do |time|
|
21
|
+
days << day_and_types(first_day_of_month - (6 - time).day, [@preview_month])
|
22
|
+
end
|
23
|
+
days
|
24
|
+
end
|
25
|
+
|
26
|
+
def days_to_current_month
|
27
|
+
days = []
|
28
|
+
last_day_of_month.day.times do |time|
|
29
|
+
type = []
|
30
|
+
day = first_day_of_month + time.day
|
31
|
+
|
32
|
+
days << day_and_types(day)
|
33
|
+
end
|
34
|
+
days
|
35
|
+
end
|
36
|
+
|
37
|
+
def days_to_next_month
|
38
|
+
fill_days = last_day_of_month.wday
|
39
|
+
fill_days = 7 if fill_days == 0
|
40
|
+
fill_days = 7 - fill_days
|
41
|
+
|
42
|
+
days = []
|
43
|
+
fill_days.times do |time|
|
44
|
+
days << day_and_types( last_day_of_month + (time + 1).day, [@next_month])
|
45
|
+
end
|
46
|
+
days
|
47
|
+
end
|
48
|
+
|
49
|
+
def first_day_of_month
|
50
|
+
@date - (@date.mday - 1).day
|
51
|
+
end
|
52
|
+
|
53
|
+
def last_day_of_month
|
54
|
+
first_day_of_month.next_month - 1.day
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def day_and_types(day, types = [])
|
60
|
+
if [6,0].include?(day.wday)
|
61
|
+
types << :weekend
|
62
|
+
end
|
63
|
+
|
64
|
+
if day.today?
|
65
|
+
types << :today
|
66
|
+
end
|
67
|
+
|
68
|
+
{:date => day, :types => types}
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class DataCalendarTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context "An instance of the DataCalendar class" do
|
6
|
+
|
7
|
+
setup do
|
8
|
+
@time = "Sun Nov 11 00:07:41 +0100 2009".to_date
|
9
|
+
@calendar = DataCalendar.new(:date => @time)
|
10
|
+
end
|
11
|
+
|
12
|
+
should "return its full first day of month" do
|
13
|
+
assert_equal "Sun, 01 Nov 2009".to_date, @calendar.first_day_of_month.to_date
|
14
|
+
end
|
15
|
+
|
16
|
+
should "return its last day of month" do
|
17
|
+
assert_equal "Mon, 30 Nov 2009".to_date, @calendar.last_day_of_month.to_date
|
18
|
+
end
|
19
|
+
|
20
|
+
should "return its days to next month" do
|
21
|
+
assert_equal 6, @calendar.days_to_next_month.size
|
22
|
+
|
23
|
+
assert_equal 'Tue, 01 Dec 2009'.to_date, @calendar.days_to_next_month.first[:date].to_date
|
24
|
+
assert_equal [:next_month], @calendar.days_to_next_month.first[:types]
|
25
|
+
|
26
|
+
assert_equal 'Sun, 06 Dec 2009'.to_date, @calendar.days_to_next_month.last[:date].to_date
|
27
|
+
assert_equal [:next_month, :weekend], @calendar.days_to_next_month.last[:types]
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: data-calendar
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- "Jos\xC3\xA9 Galisteo Ruiz"
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-11-13 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: ceritium@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.rdoc
|
24
|
+
files:
|
25
|
+
- README.rdoc
|
26
|
+
- Rakefile
|
27
|
+
- lib/data_calendar/data_calendar.rb
|
28
|
+
- lib/data_calendar/version.rb
|
29
|
+
- lib/data_calendar.rb
|
30
|
+
- test/test_helper.rb
|
31
|
+
- test/unit/data_calendar_test.rb
|
32
|
+
has_rdoc: true
|
33
|
+
homepage: http://jose.gr
|
34
|
+
licenses: []
|
35
|
+
|
36
|
+
post_install_message:
|
37
|
+
rdoc_options:
|
38
|
+
- --main
|
39
|
+
- README.rdoc
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
version:
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: "0"
|
53
|
+
version:
|
54
|
+
requirements: []
|
55
|
+
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 1.3.5
|
58
|
+
signing_key:
|
59
|
+
specification_version: 3
|
60
|
+
summary: Generates the data needed to represent a given schedule a calendar.
|
61
|
+
test_files: []
|
62
|
+
|