pseudo_date 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/lib/pseudo_date/pseudo_date.rb +10 -3
- data/pseudo_date.gemspec +7 -8
- data/test/test_pseudo_date.rb +83 -0
- metadata +8 -6
data/Rakefile
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
require 'echoe'
|
4
4
|
|
5
|
-
Echoe.new('pseudo_date', '0.1.
|
5
|
+
Echoe.new('pseudo_date', '0.1.4') do |p|
|
6
6
|
p.description = 'Date parser and container for partial or incomplete dates.'
|
7
7
|
p.url = 'http://github.com/PatrickTulskie/pseudo_date'
|
8
8
|
p.author = 'Patrick Tulskie'
|
@@ -19,12 +19,12 @@ class PseudoDate
|
|
19
19
|
@year = @year.to_i
|
20
20
|
@year = @year > Date.today.year.to_s.gsub('20','').to_i ? "19#{@year}" : "20#{@year}"
|
21
21
|
end
|
22
|
-
correct_digits
|
22
|
+
correct_digits!
|
23
23
|
@year.to_s.gsub!('~','')
|
24
24
|
end
|
25
25
|
|
26
26
|
def precision
|
27
|
-
correct_digits
|
27
|
+
correct_digits!
|
28
28
|
if @year.nil? || (@year.to_s == '0000' && @month.to_s == '00') || (@year.to_s == "8888")
|
29
29
|
"invalid"
|
30
30
|
elsif self.to_date
|
@@ -123,10 +123,17 @@ class PseudoDate
|
|
123
123
|
|
124
124
|
private
|
125
125
|
|
126
|
-
def correct_digits
|
126
|
+
def correct_digits!
|
127
127
|
@year = '0000' if @year.to_s.strip.length == 0
|
128
128
|
@month = '00' if @month.to_s.strip.length == 0
|
129
129
|
@day = '00' if @day.to_s.strip.length == 0
|
130
|
+
|
131
|
+
@day = "0#{@day}" if @day.to_s.length == 1
|
132
|
+
@month = "0#{@month}" if @month.to_s.length == 1
|
133
|
+
|
134
|
+
%w(day month year).each do |i|
|
135
|
+
@date_hash[i.to_sym] = self.send(i)
|
136
|
+
end
|
130
137
|
end
|
131
138
|
|
132
139
|
end
|
data/pseudo_date.gemspec
CHANGED
@@ -2,28 +2,27 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{pseudo_date}
|
5
|
-
s.version = "0.1.
|
5
|
+
s.version = "0.1.4"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Patrick Tulskie"]
|
9
|
-
s.date = %q{
|
9
|
+
s.date = %q{2011-07-07}
|
10
10
|
s.description = %q{Date parser and container for partial or incomplete dates.}
|
11
11
|
s.email = %q{PatrickTulskie@gmail.com}
|
12
12
|
s.extra_rdoc_files = ["README.mdown", "lib/core_extensions/object.rb", "lib/core_extensions/string.rb", "lib/pseudo_date.rb", "lib/pseudo_date/parser.rb", "lib/pseudo_date/pseudo_date.rb"]
|
13
|
-
s.files = ["Manifest", "README.mdown", "Rakefile", "lib/core_extensions/object.rb", "lib/core_extensions/string.rb", "lib/pseudo_date.rb", "lib/pseudo_date/parser.rb", "lib/pseudo_date/pseudo_date.rb", "test/test_helper.rb", "test/test_parser.rb", "
|
14
|
-
s.homepage = %q{http://github.com/PatrickTulskie/
|
13
|
+
s.files = ["Manifest", "README.mdown", "Rakefile", "lib/core_extensions/object.rb", "lib/core_extensions/string.rb", "lib/pseudo_date.rb", "lib/pseudo_date/parser.rb", "lib/pseudo_date/pseudo_date.rb", "pseudo_date.gemspec", "test/test_helper.rb", "test/test_parser.rb", "test/test_pseudo_date.rb"]
|
14
|
+
s.homepage = %q{http://github.com/PatrickTulskie/pseudo_date}
|
15
15
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Pseudo_date", "--main", "README.mdown"]
|
16
16
|
s.require_paths = ["lib"]
|
17
17
|
s.rubyforge_project = %q{pseudo_date}
|
18
|
-
s.rubygems_version = %q{1.3
|
18
|
+
s.rubygems_version = %q{1.5.3}
|
19
19
|
s.summary = %q{Date parser and container for partial or incomplete dates.}
|
20
|
-
s.test_files = ["test/test_helper.rb", "test/test_parser.rb"]
|
20
|
+
s.test_files = ["test/test_helper.rb", "test/test_parser.rb", "test/test_pseudo_date.rb"]
|
21
21
|
|
22
22
|
if s.respond_to? :specification_version then
|
23
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
24
23
|
s.specification_version = 3
|
25
24
|
|
26
|
-
if Gem::Version.new(Gem::
|
25
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
27
26
|
else
|
28
27
|
end
|
29
28
|
else
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class TestPseudoDate < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context "PseudoDate" do
|
6
|
+
|
7
|
+
setup do
|
8
|
+
@day = '25'
|
9
|
+
@month = '06'
|
10
|
+
@year = '1985'
|
11
|
+
@string_date = 'Jun 25, 1985'
|
12
|
+
end
|
13
|
+
|
14
|
+
context "partial date types" do
|
15
|
+
should "demonstrate later dates as greater than older dates" do
|
16
|
+
old_date = PseudoDate.new(:year => @year, :month => @month)
|
17
|
+
new_date = PseudoDate.new(:year => 1996, :month => @month)
|
18
|
+
assert old_date < new_date
|
19
|
+
end
|
20
|
+
should "respond properly with the spaceship operator" do
|
21
|
+
old_date = PseudoDate.new(:year => @year, :month => @month)
|
22
|
+
new_date = PseudoDate.new(:year => 1996, :month => @month)
|
23
|
+
assert_equal -1, (old_date <=> new_date)
|
24
|
+
assert_equal 1, (new_date <=> old_date)
|
25
|
+
assert_equal 0, (new_date <=> new_date)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "complete date types" do
|
30
|
+
should "demonstrate later dates as greater than older dates" do
|
31
|
+
old_date = PseudoDate.new(:year => @year, :month => @month, :day => @day)
|
32
|
+
new_date = PseudoDate.new(:year => 1996, :month => @month, :day => @day)
|
33
|
+
assert old_date < new_date
|
34
|
+
end
|
35
|
+
should "respond properly with the spaceship operator" do
|
36
|
+
old_date = PseudoDate.new(:year => @year, :month => @month, :day => @day)
|
37
|
+
new_date = PseudoDate.new(:year => 1996, :month => @month, :day => @day)
|
38
|
+
assert_equal -1, (old_date <=> new_date)
|
39
|
+
assert_equal 1, (new_date <=> old_date)
|
40
|
+
assert_equal 0, (new_date <=> new_date)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "mixed date types" do
|
45
|
+
should "demonstrate later dates as greater than older dates" do
|
46
|
+
old_date = PseudoDate.new(:year => @year, :month => @month)
|
47
|
+
new_date = PseudoDate.new(:year => 1996, :month => @month, :day => @day)
|
48
|
+
assert old_date < new_date
|
49
|
+
end
|
50
|
+
should "demonstrate invalid dates as less than complete dates" do
|
51
|
+
complete = PseudoDate.new(:year => @year, :month => @month)
|
52
|
+
invalid = PseudoDate.new("")
|
53
|
+
assert complete > invalid
|
54
|
+
end
|
55
|
+
should "respond properly with the spaceship operator" do
|
56
|
+
old_date = PseudoDate.new(:year => @year, :month => @month)
|
57
|
+
new_date = PseudoDate.new(:year => 1996, :month => @month, :day => @day)
|
58
|
+
assert_equal -1, (old_date <=> new_date)
|
59
|
+
assert_equal 1, (new_date <=> old_date)
|
60
|
+
assert_equal 0, (new_date <=> new_date)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context "date sorting" do
|
65
|
+
should "work for mixed date types" do
|
66
|
+
dates = [{ :year => 2011, :month => 5 }, '1985', nil].map { |d| PseudoDate.new(d) }
|
67
|
+
sorted = dates.sort
|
68
|
+
assert_equal '0000', sorted.first.year
|
69
|
+
assert_equal '2011', sorted.last.year
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context "converting to a hash" do
|
74
|
+
should "use double digit strings for day and month" do
|
75
|
+
date = PseudoDate.new(:day => '1', :month => '2', :year => '1980')
|
76
|
+
assert_equal '01', date.to_hash[:day]
|
77
|
+
assert_equal '02', date.to_hash[:month]
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pseudo_date
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 4
|
10
|
+
version: 0.1.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Patrick Tulskie
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-07-07 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -41,11 +41,12 @@ files:
|
|
41
41
|
- lib/pseudo_date.rb
|
42
42
|
- lib/pseudo_date/parser.rb
|
43
43
|
- lib/pseudo_date/pseudo_date.rb
|
44
|
+
- pseudo_date.gemspec
|
44
45
|
- test/test_helper.rb
|
45
46
|
- test/test_parser.rb
|
46
|
-
-
|
47
|
+
- test/test_pseudo_date.rb
|
47
48
|
has_rdoc: true
|
48
|
-
homepage: http://github.com/PatrickTulskie/
|
49
|
+
homepage: http://github.com/PatrickTulskie/pseudo_date
|
49
50
|
licenses: []
|
50
51
|
|
51
52
|
post_install_message:
|
@@ -87,3 +88,4 @@ summary: Date parser and container for partial or incomplete dates.
|
|
87
88
|
test_files:
|
88
89
|
- test/test_helper.rb
|
89
90
|
- test/test_parser.rb
|
91
|
+
- test/test_pseudo_date.rb
|