chronomize 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/chronomize.gemspec +1 -1
- data/lib/chronomize.rb +5 -4
- data/spec/chronomize_spec.rb +13 -12
- metadata +7 -7
data/chronomize.gemspec
CHANGED
data/lib/chronomize.rb
CHANGED
@@ -31,7 +31,8 @@ class Chronomize
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def label_for(date, direction = nil)
|
34
|
-
|
34
|
+
label = chronicality(date)
|
35
|
+
pieces = label ? [label] : [format(date)]
|
35
36
|
pieces.push forward if direction == :forward
|
36
37
|
pieces.unshift backward if direction == :backward
|
37
38
|
pieces.compact.join(" ")
|
@@ -43,11 +44,11 @@ class Chronomize
|
|
43
44
|
|
44
45
|
def chronicality(date)
|
45
46
|
if Date.yesterday?(date)
|
46
|
-
|
47
|
+
yesterday
|
47
48
|
elsif Date.today?(date)
|
48
|
-
|
49
|
+
today
|
49
50
|
elsif Date.tomorrow?(date)
|
50
|
-
|
51
|
+
tomorrow
|
51
52
|
end
|
52
53
|
end
|
53
54
|
|
data/spec/chronomize_spec.rb
CHANGED
@@ -11,20 +11,21 @@ describe Chronomize do
|
|
11
11
|
let(:feb9) { Date.new(2012, 2, 9) }
|
12
12
|
|
13
13
|
before(:each) { Timecop.freeze(feb7) }
|
14
|
+
after(:each) { Timecop.return }
|
14
15
|
|
15
16
|
context "today" do
|
16
17
|
subject { Chronomize.new(feb7) }
|
17
18
|
|
18
|
-
its(:previous) { should eq('
|
19
|
-
its(:current) { should eq('
|
20
|
-
its(:next) { should eq('
|
19
|
+
its(:previous) { should eq('yesterday') }
|
20
|
+
its(:current) { should eq('today') }
|
21
|
+
its(:next) { should eq('tomorrow') }
|
21
22
|
end
|
22
23
|
|
23
24
|
context "tomorrow" do
|
24
25
|
subject { Chronomize.new(feb8) }
|
25
26
|
|
26
|
-
its(:previous) { should eq('
|
27
|
-
its(:current) { should eq('
|
27
|
+
its(:previous) { should eq('today') }
|
28
|
+
its(:current) { should eq('tomorrow') }
|
28
29
|
its(:next) { should eq('February 9, 2012') }
|
29
30
|
end
|
30
31
|
|
@@ -32,8 +33,8 @@ describe Chronomize do
|
|
32
33
|
subject { Chronomize.new(feb6) }
|
33
34
|
|
34
35
|
its(:previous) { should eq('February 5, 2012') }
|
35
|
-
its(:current) { should eq('
|
36
|
-
its(:next) { should eq('
|
36
|
+
its(:current) { should eq('yesterday') }
|
37
|
+
its(:next) { should eq('today') }
|
37
38
|
end
|
38
39
|
|
39
40
|
context "last week" do
|
@@ -46,16 +47,16 @@ describe Chronomize do
|
|
46
47
|
context "with symbols" do
|
47
48
|
subject { Chronomize.new(feb6, :previous => '<~', :next => '~>') }
|
48
49
|
its(:previous) { should eq('<~ February 5, 2012') }
|
49
|
-
its(:current) { should eq('
|
50
|
-
its(:next) { should eq('
|
50
|
+
its(:current) { should eq('yesterday') }
|
51
|
+
its(:next) { should eq('today ~>') }
|
51
52
|
end
|
52
53
|
|
53
54
|
context "with alternate day names" do
|
54
55
|
subject { Chronomize.new(feb7, :today => "aujourd'hui", :yesterday => 'hier', :tomorrow => 'demain') }
|
55
56
|
|
56
|
-
its(:previous) { should eq('
|
57
|
-
its(:current) { should eq('
|
58
|
-
its(:next) { should eq('
|
57
|
+
its(:previous) { should eq('hier') }
|
58
|
+
its(:current) { should eq('aujourd\'hui') }
|
59
|
+
its(:next) { should eq('demain') }
|
59
60
|
end
|
60
61
|
|
61
62
|
context "without day names" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chronomize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-03-07 00:00:00.
|
12
|
+
date: 2012-03-07 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70305360568220 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70305360568220
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: timecop
|
27
|
-
requirement: &
|
27
|
+
requirement: &70305360567780 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70305360567780
|
36
36
|
description: Creates labels for a window of dates, with knowledge about it's relationship
|
37
37
|
to the current date.
|
38
38
|
email:
|
@@ -70,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
70
|
version: '0'
|
71
71
|
requirements: []
|
72
72
|
rubyforge_project: chronomize
|
73
|
-
rubygems_version: 1.8.
|
73
|
+
rubygems_version: 1.8.10
|
74
74
|
signing_key:
|
75
75
|
specification_version: 3
|
76
76
|
summary: Simple dateful navigation.
|