dude_weak 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rspec +1 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/dude_weak.gemspec +21 -0
- data/lib/dude_weak.rb +66 -0
- data/lib/dude_weak/version.rb +3 -0
- data/spec/week_spec.rb +54 -0
- metadata +79 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use --create 1.9.3@dude_weak
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Joe Sak
|
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
|
+
# DudeWeak
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'dude_weak'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install dude_weak
|
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/dude_weak.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/dude_weak/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Joe Sak"]
|
6
|
+
gem.email = ["joe@neotericdesign.com"]
|
7
|
+
gem.description = %q{A simple Week class based on ActiveSupport Time Calculations}
|
8
|
+
gem.summary = %q{A small week building class}
|
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 = "dude_weak"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = DudeWeak::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency 'activesupport'
|
19
|
+
|
20
|
+
gem.add_development_dependency 'rspec'
|
21
|
+
end
|
data/lib/dude_weak.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
require "dude_weak/version"
|
2
|
+
require 'active_support/all'
|
3
|
+
require 'ostruct'
|
4
|
+
require 'date'
|
5
|
+
|
6
|
+
class Week
|
7
|
+
attr_accessor :date, :time
|
8
|
+
|
9
|
+
def initialize(time)
|
10
|
+
@time = time
|
11
|
+
@date = time.to_date
|
12
|
+
end
|
13
|
+
|
14
|
+
def year
|
15
|
+
@date.cwyear
|
16
|
+
end
|
17
|
+
|
18
|
+
def number
|
19
|
+
@date.cweek
|
20
|
+
end
|
21
|
+
|
22
|
+
def next
|
23
|
+
self.class.new(@date.next_week)
|
24
|
+
end
|
25
|
+
|
26
|
+
def previous
|
27
|
+
self.class.new(@date.prev_week)
|
28
|
+
end
|
29
|
+
|
30
|
+
def monday
|
31
|
+
@time.monday
|
32
|
+
end
|
33
|
+
|
34
|
+
def days
|
35
|
+
@days ||= []
|
36
|
+
return @days unless @days.empty?
|
37
|
+
build_days
|
38
|
+
@days
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
def build_days
|
43
|
+
7.times do |n|
|
44
|
+
@days << Day.new(:date => current_date(n),
|
45
|
+
:dayname => current_dayname(n))
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def current_date(n)
|
50
|
+
monday.advance(:days => n)
|
51
|
+
end
|
52
|
+
|
53
|
+
def current_dayname(n)
|
54
|
+
current_date(n).strftime('%A')
|
55
|
+
end
|
56
|
+
|
57
|
+
class Day
|
58
|
+
def initialize(attrs)
|
59
|
+
@source = OpenStruct.new(attrs)
|
60
|
+
end
|
61
|
+
|
62
|
+
def method_missing(method, *args, &block)
|
63
|
+
@source.send(method, *args, &block)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/spec/week_spec.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'dude_weak'
|
2
|
+
|
3
|
+
describe Week do
|
4
|
+
let(:today) { Time.parse('Jul 11, 2012') }
|
5
|
+
let(:week) { Week.new(today) }
|
6
|
+
|
7
|
+
it "returns its monday" do
|
8
|
+
week.monday.should == Time.parse('Jul 9, 2012')
|
9
|
+
end
|
10
|
+
|
11
|
+
it "returns its number" do
|
12
|
+
week.number.should == 28
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns its year" do
|
16
|
+
week.year.should == 2012
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns its next week" do
|
20
|
+
week = Week.new(Time.parse('Dec 29, 2012'))
|
21
|
+
|
22
|
+
next_week = week.next
|
23
|
+
next_week.year.should == 2013
|
24
|
+
next_week.number.should == 1
|
25
|
+
end
|
26
|
+
|
27
|
+
it "returns its previous week" do
|
28
|
+
# weeks start on mondays, Jan 2 2012 is a Monday
|
29
|
+
week = Week.new(Time.parse('Jan 2, 2012'))
|
30
|
+
|
31
|
+
last_week = week.previous
|
32
|
+
last_week.year.should == 2011
|
33
|
+
last_week.number.should == 52
|
34
|
+
end
|
35
|
+
|
36
|
+
it "returns its days" do
|
37
|
+
daynames = %w(Monday
|
38
|
+
Tuesday
|
39
|
+
Wednesday
|
40
|
+
Thursday
|
41
|
+
Friday
|
42
|
+
Saturday
|
43
|
+
Sunday)
|
44
|
+
week.days.each_with_index do |day, i|
|
45
|
+
day.dayname.should == daynames[i]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
it "allows dynamic attributes in its days" do
|
50
|
+
week.days.first.things = [1, 2, 3]
|
51
|
+
week.days.first.things.should == [1, 2, 3]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dude_weak
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Joe Sak
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-07-11 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activesupport
|
16
|
+
requirement: &70157249819360 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70157249819360
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &70157249818940 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70157249818940
|
36
|
+
description: A simple Week class based on ActiveSupport Time Calculations
|
37
|
+
email:
|
38
|
+
- joe@neotericdesign.com
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- .gitignore
|
44
|
+
- .rspec
|
45
|
+
- .rvmrc
|
46
|
+
- Gemfile
|
47
|
+
- LICENSE
|
48
|
+
- README.md
|
49
|
+
- Rakefile
|
50
|
+
- dude_weak.gemspec
|
51
|
+
- lib/dude_weak.rb
|
52
|
+
- lib/dude_weak/version.rb
|
53
|
+
- spec/week_spec.rb
|
54
|
+
homepage: ''
|
55
|
+
licenses: []
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ! '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
requirements: []
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 1.8.15
|
75
|
+
signing_key:
|
76
|
+
specification_version: 3
|
77
|
+
summary: A small week building class
|
78
|
+
test_files:
|
79
|
+
- spec/week_spec.rb
|