tony_time 1.0.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/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README +9 -0
- data/Rakefile +1 -0
- data/lib/tony_time/tony_time.rb +31 -0
- data/lib/tony_time/version.rb +3 -0
- data/lib/tony_time.rb +2 -0
- data/spec/spec_helper.rb +6 -0
- data/spec/tony_time_spec.rb +67 -0
- data/tony_time.gemspec +24 -0
- metadata +88 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
tony_time is a Ruby *1.9.x* gem that driver tonyti.me
|
2
|
+
|
3
|
+
"Tony Time" follows these rules:
|
4
|
+
- Falls on 4PM
|
5
|
+
- Not during the weekend
|
6
|
+
|
7
|
+
It provides two instance methods:
|
8
|
+
- next_tony_time: Returns the next available Tony Time in the form of a DateTime object.
|
9
|
+
- during_tony_time?: Returns a boolean if the current time is 0-5 minutes after the current Tony Time.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class TonyTime
|
2
|
+
require "date"
|
3
|
+
|
4
|
+
def next_tony_time
|
5
|
+
return @next_tony_time if @next_tony_time
|
6
|
+
@next_tony_time = today_tony_time
|
7
|
+
if now > today_tony_time || is_weekend?(@next_tony_time)
|
8
|
+
begin
|
9
|
+
@next_tony_time += 1
|
10
|
+
end while is_weekend?(@next_tony_time)
|
11
|
+
end
|
12
|
+
@next_tony_time
|
13
|
+
end
|
14
|
+
|
15
|
+
def during_tony_time?
|
16
|
+
!is_weekend?(now) && now.hour == 16 && now.minute <= 5
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
def today_tony_time
|
21
|
+
@today_tony_time ||= DateTime.new(now.year, now.month, now.day, 16)
|
22
|
+
end
|
23
|
+
|
24
|
+
def is_weekend?(datetime)
|
25
|
+
[0,6].include? datetime.wday # 0 = Sunday, 6 = Saturday
|
26
|
+
end
|
27
|
+
|
28
|
+
def now
|
29
|
+
@now ||= DateTime.now
|
30
|
+
end
|
31
|
+
end
|
data/lib/tony_time.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
def setup_now(year, month, day, hour, minute = 0, second = 0)
|
4
|
+
@tony_time.stub!(:now).and_return(DateTime.new(year, month, day, hour, minute, second))
|
5
|
+
end
|
6
|
+
|
7
|
+
describe TonyTime do
|
8
|
+
before(:each) do
|
9
|
+
@tony_time = TonyTime.new
|
10
|
+
end
|
11
|
+
describe '#today_tony_time' do
|
12
|
+
it 'should return 11/3/2011 4:00PM' do
|
13
|
+
setup_now(2011, 11, 3, 11, 30)
|
14
|
+
@tony_time.send(:today_tony_time).should == DateTime.new(2011, 11, 3, 16)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should return 11/4/2011 4:00PM' do
|
18
|
+
setup_now(2011, 11, 4, 19, 23)
|
19
|
+
@tony_time.send(:today_tony_time).should == DateTime.new(2011, 11, 4, 16)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#next_tony_time' do
|
24
|
+
it 'should return 11/3/2011 4:00PM (Thursday) if #now is 11/3/2011 2:00PM (Thursday)' do
|
25
|
+
setup_now(2011, 11, 3, 14)
|
26
|
+
@tony_time.next_tony_time.should == DateTime.new(2011, 11, 3, 16)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should return 11/3/2011 4:00PM (Thursday) if #now is 11/2/2011 5:00PM (Wednesday)' do
|
30
|
+
setup_now(2011, 11, 2, 17)
|
31
|
+
@tony_time.next_tony_time.should == DateTime.new(2011, 11, 3, 16)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should return 11/7/2011 4:00PM (Monday) if #now is 11/4/2011 5:00PM (Friday)' do
|
35
|
+
setup_now(2011, 11, 4, 17)
|
36
|
+
@tony_time.next_tony_time.should == DateTime.new(2011, 11, 7, 16)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should return 11/7/2011 4:00PM (Monday) if #now is 11/5/2011 5:00PM (Saturday)' do
|
40
|
+
setup_now(2011, 11, 5, 17)
|
41
|
+
@tony_time.next_tony_time.should == DateTime.new(2011, 11, 7, 16)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#during_tony_time?' do
|
46
|
+
it "should return true if it's 0-5 minutes after Tony Time" do
|
47
|
+
(0..5).each do |minute|
|
48
|
+
setup_now(2011, 11, 3, 16, minute)
|
49
|
+
@tony_time.during_tony_time?.should be_true
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should return false if it's not 0-5 minutes after Tony Time" do
|
54
|
+
(6..59).each do |minute|
|
55
|
+
setup_now(2011, 11, 3, 16, minute)
|
56
|
+
@tony_time.during_tony_time?.should be_false
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should return false if it's 0-5 minutes after Tony Time on the weekend" do
|
61
|
+
(0..5).each do |minute|
|
62
|
+
setup_now(2011, 11, 6, 16, minute)
|
63
|
+
@tony_time.during_tony_time?.should be_false
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/tony_time.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "tony_time/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "tony_time"
|
7
|
+
s.version = TonyTime::VERSION
|
8
|
+
s.authors = ["Tony Drake"]
|
9
|
+
s.email = ["t27duck@gmail.com"]
|
10
|
+
s.homepage = "http://tonyti.me"
|
11
|
+
s.summary = %q{Determines when the Tomy Time is}
|
12
|
+
s.description = %q{Gem that drives tonyti.me}
|
13
|
+
|
14
|
+
s.rubyforge_project = "tony_time"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
s.add_development_dependency "rspec"
|
23
|
+
# s.add_runtime_dependency "rest-client"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tony_time
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Tony Drake
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-11-06 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rspec
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
type: :development
|
33
|
+
version_requirements: *id001
|
34
|
+
description: Gem that drives tonyti.me
|
35
|
+
email:
|
36
|
+
- t27duck@gmail.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files: []
|
42
|
+
|
43
|
+
files:
|
44
|
+
- .gitignore
|
45
|
+
- Gemfile
|
46
|
+
- README
|
47
|
+
- Rakefile
|
48
|
+
- lib/tony_time.rb
|
49
|
+
- lib/tony_time/tony_time.rb
|
50
|
+
- lib/tony_time/version.rb
|
51
|
+
- spec/spec_helper.rb
|
52
|
+
- spec/tony_time_spec.rb
|
53
|
+
- tony_time.gemspec
|
54
|
+
homepage: http://tonyti.me
|
55
|
+
licenses: []
|
56
|
+
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
hash: 3
|
68
|
+
segments:
|
69
|
+
- 0
|
70
|
+
version: "0"
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
hash: 3
|
77
|
+
segments:
|
78
|
+
- 0
|
79
|
+
version: "0"
|
80
|
+
requirements: []
|
81
|
+
|
82
|
+
rubyforge_project: tony_time
|
83
|
+
rubygems_version: 1.8.10
|
84
|
+
signing_key:
|
85
|
+
specification_version: 3
|
86
|
+
summary: Determines when the Tomy Time is
|
87
|
+
test_files: []
|
88
|
+
|