cal 0.0.1
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/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/cal.gemspec +21 -0
- data/lib/cal.rb +9 -0
- data/lib/cal/day.rb +16 -0
- data/lib/cal/ender.rb +44 -0
- data/lib/cal/month.rb +17 -0
- data/lib/cal/version.rb +5 -0
- data/spec/cal/day_spec.rb +17 -0
- data/spec/cal/ender_spec.rb +62 -0
- data/spec/cal/month_spec.rb +23 -0
- data/spec/spec_helper.rb +2 -0
- metadata +96 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Austin Schneider
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Cal
|
2
|
+
|
3
|
+
A low level calendar engine.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'cal'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install cal
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/cal.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/cal/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Austin Schneider"]
|
6
|
+
gem.email = ["austinthecoder@gmail.com"]
|
7
|
+
gem.description = "A low level calendar engine."
|
8
|
+
gem.summary = "A low level calendar engine."
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "cal"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Cal::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency "activesupport", ">= 2"
|
19
|
+
|
20
|
+
gem.add_development_dependency "rspec", "~> 2.10.0"
|
21
|
+
end
|
data/lib/cal.rb
ADDED
data/lib/cal/day.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
module Cal
|
2
|
+
class Day
|
3
|
+
|
4
|
+
def initialize(calendar, date)
|
5
|
+
@calendar = calendar
|
6
|
+
@date = date
|
7
|
+
end
|
8
|
+
|
9
|
+
attr_reader :calendar, :date
|
10
|
+
|
11
|
+
def ==(other)
|
12
|
+
other.is_a?(Day) && other.calendar == calendar && other.date == date
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
data/lib/cal/ender.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'active_support/time'
|
2
|
+
require 'active_support/core_ext/array/grouping'
|
3
|
+
|
4
|
+
module Cal
|
5
|
+
class Ender
|
6
|
+
|
7
|
+
def initialize(date)
|
8
|
+
@date = date
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_reader :date
|
12
|
+
|
13
|
+
def ==(other)
|
14
|
+
other.is_a?(Ender) && other.date == date
|
15
|
+
end
|
16
|
+
|
17
|
+
def month
|
18
|
+
@mont ||= Month.new self
|
19
|
+
end
|
20
|
+
|
21
|
+
def weeks
|
22
|
+
@weeks ||= days.in_groups_of 7
|
23
|
+
end
|
24
|
+
|
25
|
+
def days
|
26
|
+
@days ||= begin
|
27
|
+
day = date.beginning_of_month.beginning_of_week :sunday
|
28
|
+
last_day = date.end_of_month.end_of_week :sunday
|
29
|
+
|
30
|
+
days = []
|
31
|
+
while day <= last_day
|
32
|
+
days << Day.new(self, day)
|
33
|
+
day = day.tomorrow
|
34
|
+
end
|
35
|
+
days
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def week_headings
|
40
|
+
@week_headings ||= %w[Sunday Monday Tuesday Wednesday Thursday Friday Saturday]
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
data/lib/cal/month.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Cal::Day do
|
4
|
+
subject { described_class.new @calendar, @date }
|
5
|
+
|
6
|
+
before do
|
7
|
+
@calendar = OpenStruct.new :date => Date.parse("2012-01-05")
|
8
|
+
@date = Date.parse("2012-01-05")
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "==" do
|
12
|
+
it "is true with another day with the same calendar and date" do
|
13
|
+
subject.should == described_class.new(@calendar, @date)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Cal::Ender do
|
4
|
+
subject { described_class.new @date }
|
5
|
+
|
6
|
+
before do
|
7
|
+
@date = Date.parse("2012-02-23")
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "=" do
|
11
|
+
it "is true with another calendar with the same date" do
|
12
|
+
subject.should == described_class.new(@date)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "date" do
|
17
|
+
it "is the date given" do
|
18
|
+
subject.date.should == @date
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "month" do
|
23
|
+
it "is a month" do
|
24
|
+
subject.month.should be_a(Cal::Month)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "has a reference to the calendar" do
|
28
|
+
subject.month.calendar.should == subject
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "weeks" do
|
33
|
+
it "is the days in groups of 7" do
|
34
|
+
subject.weeks.should == [
|
35
|
+
%w[01-29 01-30 01-31 02-01 02-02 02-03 02-04].map { |s| Cal::Day.new subject, Date.parse("2012-#{s}") },
|
36
|
+
%w[02-05 02-06 02-07 02-08 02-09 02-10 02-11].map { |s| Cal::Day.new subject, Date.parse("2012-#{s}") },
|
37
|
+
%w[02-12 02-13 02-14 02-15 02-16 02-17 02-18].map { |s| Cal::Day.new subject, Date.parse("2012-#{s}") },
|
38
|
+
%w[02-19 02-20 02-21 02-22 02-23 02-24 02-25].map { |s| Cal::Day.new subject, Date.parse("2012-#{s}") },
|
39
|
+
%w[02-26 02-27 02-28 02-29 03-01 03-02 03-03].map { |s| Cal::Day.new subject, Date.parse("2012-#{s}") }
|
40
|
+
]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "days" do
|
45
|
+
it "is an array of all the viewable days" do
|
46
|
+
jan = %w[01-29 01-30 01-31]
|
47
|
+
feb = %w[02-01 02-02 02-03 02-04 02-05 02-06 02-07 02-08 02-09 02-10 02-11 02-12 02-13 02-14 02-15 02-16 02-17 02-18 02-19 02-20 02-21 02-22 02-23 02-24 02-25 02-26 02-27 02-28 02-29]
|
48
|
+
mar = %w[03-01 03-02 03-03]
|
49
|
+
|
50
|
+
subject.days.should == (jan + feb + mar).map do |s|
|
51
|
+
Cal::Day.new subject, Date.parse("2012-#{s}")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "week_headings" do
|
57
|
+
it "returns the days of the week" do
|
58
|
+
subject.week_headings.should == %w[Sunday Monday Tuesday Wednesday Thursday Friday Saturday]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Cal::Month do
|
4
|
+
|
5
|
+
subject { Cal::Month.new @calendar }
|
6
|
+
|
7
|
+
before do
|
8
|
+
@calendar = OpenStruct.new
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "name" do
|
12
|
+
it "is the name of the month" do
|
13
|
+
[
|
14
|
+
[Date.parse('2012-01-21'), 'January'],
|
15
|
+
[Date.parse('2012-02-21'), 'February']
|
16
|
+
].each do |date, name|
|
17
|
+
@calendar.date = date
|
18
|
+
subject.name.should == name
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cal
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Austin Schneider
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-03 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activesupport
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '2'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '2'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 2.10.0
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.10.0
|
46
|
+
description: A low level calendar engine.
|
47
|
+
email:
|
48
|
+
- austinthecoder@gmail.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- cal.gemspec
|
59
|
+
- lib/cal.rb
|
60
|
+
- lib/cal/day.rb
|
61
|
+
- lib/cal/ender.rb
|
62
|
+
- lib/cal/month.rb
|
63
|
+
- lib/cal/version.rb
|
64
|
+
- spec/cal/day_spec.rb
|
65
|
+
- spec/cal/ender_spec.rb
|
66
|
+
- spec/cal/month_spec.rb
|
67
|
+
- spec/spec_helper.rb
|
68
|
+
homepage: ''
|
69
|
+
licenses: []
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ! '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
requirements: []
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 1.8.21
|
89
|
+
signing_key:
|
90
|
+
specification_version: 3
|
91
|
+
summary: A low level calendar engine.
|
92
|
+
test_files:
|
93
|
+
- spec/cal/day_spec.rb
|
94
|
+
- spec/cal/ender_spec.rb
|
95
|
+
- spec/cal/month_spec.rb
|
96
|
+
- spec/spec_helper.rb
|