pseudo_date 0.1.4 → 0.1.5
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 +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +24 -0
- data/Rakefile +0 -12
- data/benchmark/pseudo_date_benchmark.rb +17 -0
- data/lib/pseudo_date/pseudo_date.rb +13 -4
- data/lib/pseudo_date/version.rb +3 -0
- data/pseudo_date.gemspec +17 -26
- data/spec/parser_spec.rb +149 -0
- data/spec/pseudo_date_spec.rb +88 -0
- data/{test/test_helper.rb → spec/spec_helper.rb} +1 -2
- metadata +52 -62
- data/test/test_parser.rb +0 -153
- data/test/test_pseudo_date.rb +0 -83
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.gem
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
pseudo_date (0.1.5)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.2.4)
|
10
|
+
rspec (2.13.0)
|
11
|
+
rspec-core (~> 2.13.0)
|
12
|
+
rspec-expectations (~> 2.13.0)
|
13
|
+
rspec-mocks (~> 2.13.0)
|
14
|
+
rspec-core (2.13.1)
|
15
|
+
rspec-expectations (2.13.0)
|
16
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
17
|
+
rspec-mocks (2.13.1)
|
18
|
+
|
19
|
+
PLATFORMS
|
20
|
+
ruby
|
21
|
+
|
22
|
+
DEPENDENCIES
|
23
|
+
pseudo_date!
|
24
|
+
rspec
|
data/Rakefile
CHANGED
@@ -1,13 +1 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'rake'
|
3
|
-
require 'echoe'
|
4
|
-
|
5
|
-
Echoe.new('pseudo_date', '0.1.4') do |p|
|
6
|
-
p.description = 'Date parser and container for partial or incomplete dates.'
|
7
|
-
p.url = 'http://github.com/PatrickTulskie/pseudo_date'
|
8
|
-
p.author = 'Patrick Tulskie'
|
9
|
-
p.email = 'PatrickTulskie@gmail.com'
|
10
|
-
p.ignore_pattern = ['tmp/*', 'script/*', 'lib/main.rb']
|
11
|
-
end
|
12
|
-
|
13
1
|
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'benchmark'
|
3
|
+
require '../lib/pseudo_date'
|
4
|
+
include Benchmark
|
5
|
+
|
6
|
+
bm do |bench|
|
7
|
+
bench.report('null ') { 1000.times { |i| i } }
|
8
|
+
bench.report('19850625 ') { 1000.times { PseudoDate.new('19850625') } }
|
9
|
+
bench.report('1985-25-06 ') { 1000.times { PseudoDate.new('1985-25-06') } }
|
10
|
+
bench.report('06-25-1985 ') { 1000.times { PseudoDate.new('06-25-1985') } }
|
11
|
+
bench.report('25-06-1985 ') { 1000.times { PseudoDate.new('25-06-1985') } }
|
12
|
+
bench.report('06/25/1985 ') { 1000.times { PseudoDate.new('06/25/1985') } }
|
13
|
+
bench.report('06/1985 ') { 1000.times { PseudoDate.new('06/1985') } }
|
14
|
+
bench.report('85 ') { 1000.times { PseudoDate.new('85') } }
|
15
|
+
bench.report('1985 ') { 1000.times { PseudoDate.new('1985') } }
|
16
|
+
bench.report('Jun 25, 1985 ') { 1000.times { PseudoDate.new('Jun 25, 1985') } }
|
17
|
+
end
|
@@ -42,7 +42,16 @@ class PseudoDate
|
|
42
42
|
# = Boolean Questions =
|
43
43
|
# =====================
|
44
44
|
def valid?
|
45
|
-
!(@date_hash.nil? || @date_hash.empty?)
|
45
|
+
!(@date_hash.nil? || @date_hash.empty?) && self.present?
|
46
|
+
end
|
47
|
+
|
48
|
+
def blank?
|
49
|
+
(@year.to_s == '0000' && @month.to_s == '00' && @day.to_s == '00')
|
50
|
+
end
|
51
|
+
alias_method :empty?, :blank?
|
52
|
+
|
53
|
+
def present?
|
54
|
+
!self.blank?
|
46
55
|
end
|
47
56
|
|
48
57
|
# ====================
|
@@ -124,11 +133,11 @@ class PseudoDate
|
|
124
133
|
private
|
125
134
|
|
126
135
|
def correct_digits!
|
127
|
-
@year
|
136
|
+
@year = '0000' if @year.to_s.strip.length == 0
|
128
137
|
@month = '00' if @month.to_s.strip.length == 0
|
129
|
-
@day
|
138
|
+
@day = '00' if @day.to_s.strip.length == 0
|
130
139
|
|
131
|
-
@day
|
140
|
+
@day = "0#{@day}" if @day.to_s.length == 1
|
132
141
|
@month = "0#{@month}" if @month.to_s.length == 1
|
133
142
|
|
134
143
|
%w(day month year).each do |i|
|
data/pseudo_date.gemspec
CHANGED
@@ -1,30 +1,21 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'pseudo_date/version'
|
2
5
|
|
3
|
-
Gem::Specification.new do |
|
4
|
-
|
5
|
-
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "pseudo_date"
|
8
|
+
gem.version = PseudoDate::VERSION
|
9
|
+
gem.authors = ["Patrick Tulskie"]
|
10
|
+
gem.email = ["patricktulskie@gmail.com"]
|
11
|
+
gem.description = %q{Date parser and container for partial or incomplete dates.}
|
12
|
+
gem.summary = %q{Date parser and container for partial or incomplete dates.}
|
13
|
+
gem.homepage = "http://github.com/PatrickTulskie/pseudo_date"
|
6
14
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
-
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Pseudo_date", "--main", "README.mdown"]
|
16
|
-
s.require_paths = ["lib"]
|
17
|
-
s.rubyforge_project = %q{pseudo_date}
|
18
|
-
s.rubygems_version = %q{1.5.3}
|
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", "test/test_pseudo_date.rb"]
|
21
|
-
|
22
|
-
if s.respond_to? :specification_version then
|
23
|
-
s.specification_version = 3
|
24
|
-
|
25
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
26
|
-
else
|
27
|
-
end
|
28
|
-
else
|
29
|
-
end
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_development_dependency("rspec")
|
30
21
|
end
|
data/spec/parser_spec.rb
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe "PseudoDate Parsing" do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@day = '25'
|
7
|
+
@month = '06'
|
8
|
+
@year = '1985'
|
9
|
+
@string_date = 'Jun 25, 1985'
|
10
|
+
end
|
11
|
+
|
12
|
+
context "date hash" do
|
13
|
+
it "should parse an exact hash" do
|
14
|
+
pd = PseudoDate.new(:year => @year, :day => @day, :month => @month)
|
15
|
+
pd.day.should == @day
|
16
|
+
pd.month.should == @month
|
17
|
+
pd.year.should == @year
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should parse a hash inexact keys" do
|
21
|
+
pd = PseudoDate.new('Year' => @year, 'day' => @day, :Month => @month)
|
22
|
+
pd.day.should == @day
|
23
|
+
pd.month.should == @month
|
24
|
+
pd.year.should == @year
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# 19850625
|
29
|
+
context "yearmonthday" do
|
30
|
+
it 'should be exact precision' do
|
31
|
+
PseudoDate.new("#{@year}#{@month}#{@day}").precision.should == 'exact'
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should match original input' do
|
35
|
+
pd = PseudoDate.new("#{@year}#{@month}#{@day}")
|
36
|
+
pd.day.should == @day
|
37
|
+
pd.month.should == @month
|
38
|
+
pd.year.should == @year
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# 1985-25-06
|
43
|
+
context "year-day-month" do
|
44
|
+
it 'should be exact precision' do
|
45
|
+
PseudoDate.new("#{@year}-#{@day}-#{@month}").precision.should == 'exact'
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should match original input' do
|
49
|
+
pd = PseudoDate.new("#{@year}-#{@day}-#{@month}")
|
50
|
+
pd.day.should == @day
|
51
|
+
pd.month.should == @month
|
52
|
+
pd.year.should == @year
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# 06-25-1985
|
57
|
+
context "month-day-year" do
|
58
|
+
it 'should be exact precision' do
|
59
|
+
PseudoDate.new("#{@month}-#{@day}-#{@year}").precision.should == 'exact'
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should match original input' do
|
63
|
+
pd = PseudoDate.new("#{@month}-#{@day}-#{@year}")
|
64
|
+
pd.day.should == @day
|
65
|
+
pd.month.should == @month
|
66
|
+
pd.year.should == @year
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# 25-06-1985
|
71
|
+
context "day-month-year" do
|
72
|
+
it 'should be exact precision' do
|
73
|
+
PseudoDate.new("#{@day}-#{@month}-#{@year}").precision.should == 'exact'
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'should match original input' do
|
77
|
+
pd = PseudoDate.new("#{@day}-#{@month}-#{@year}")
|
78
|
+
pd.day.should == @day
|
79
|
+
pd.month.should == @month
|
80
|
+
pd.year.should == @year
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
# 06/25/1985
|
85
|
+
context "month/day/year" do
|
86
|
+
it 'should be exact precision' do
|
87
|
+
PseudoDate.new("#{@month}/#{@day}/#{@year}").precision.should == 'exact'
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'should match original input' do
|
91
|
+
pd = PseudoDate.new("#{@month}/#{@day}/#{@year}")
|
92
|
+
pd.day.should == @day
|
93
|
+
pd.month.should == @month
|
94
|
+
pd.year.should == @year
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# 06/1985
|
99
|
+
context "month/year" do
|
100
|
+
it 'should be partial precision' do
|
101
|
+
PseudoDate.new("#{@month}/#{@year}").precision.should == 'year_month'
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'should match original input' do
|
105
|
+
pd = PseudoDate.new("#{@month}/#{@year}")
|
106
|
+
pd.month.should == @month
|
107
|
+
pd.year.should == @year
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
# 85
|
112
|
+
context "two digit year" do
|
113
|
+
it 'should be year precision' do
|
114
|
+
PseudoDate.new("85").precision == 'year'
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'should match original input' do
|
118
|
+
pd = PseudoDate.new("85")
|
119
|
+
pd.year.should == @year
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
# 1985
|
124
|
+
context "four digit year" do
|
125
|
+
it 'should be year precision' do
|
126
|
+
PseudoDate.new(@year).precision.should == 'year'
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'should match original input' do
|
130
|
+
pd = PseudoDate.new(@year)
|
131
|
+
pd.year.should == @year
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
# Jun 25, 1985
|
136
|
+
context "string date" do
|
137
|
+
it 'should be exact precision' do
|
138
|
+
PseudoDate.new(@string_date).precision.should == 'exact'
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'should match original input' do
|
142
|
+
pd = PseudoDate.new(@string_date)
|
143
|
+
pd.day.should == @day
|
144
|
+
pd.month.should == @month
|
145
|
+
pd.year.should == @year
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe "PseudoDate" do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@day = '25'
|
7
|
+
@month = '06'
|
8
|
+
@year = '1985'
|
9
|
+
@string_date = 'Jun 25, 1985'
|
10
|
+
end
|
11
|
+
|
12
|
+
context "blank dates" do
|
13
|
+
subject { PseudoDate.new("") }
|
14
|
+
|
15
|
+
it { should be_blank }
|
16
|
+
it { should be_empty }
|
17
|
+
it { should_not be_present }
|
18
|
+
it { should_not be_valid }
|
19
|
+
end
|
20
|
+
|
21
|
+
context "partial date types" do
|
22
|
+
it "should demonstrate later dates as greater than older dates" do
|
23
|
+
old_date = PseudoDate.new(:year => @year, :month => @month)
|
24
|
+
new_date = PseudoDate.new(:year => 1996, :month => @month)
|
25
|
+
(old_date < new_date).should be_true
|
26
|
+
end
|
27
|
+
it "should respond properly with the spaceship operator" do
|
28
|
+
old_date = PseudoDate.new(:year => @year, :month => @month)
|
29
|
+
new_date = PseudoDate.new(:year => 1996, :month => @month)
|
30
|
+
(old_date <=> new_date).should == -1
|
31
|
+
(new_date <=> old_date).should == 1
|
32
|
+
(new_date <=> new_date).should == 0
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "complete date types" do
|
37
|
+
it "should demonstrate later dates as greater than older dates" do
|
38
|
+
old_date = PseudoDate.new(:year => @year, :month => @month, :day => @day)
|
39
|
+
new_date = PseudoDate.new(:year => 1996, :month => @month, :day => @day)
|
40
|
+
(old_date < new_date).should be_true
|
41
|
+
end
|
42
|
+
it "should respond properly with the spaceship operator" do
|
43
|
+
old_date = PseudoDate.new(:year => @year, :month => @month, :day => @day)
|
44
|
+
new_date = PseudoDate.new(:year => 1996, :month => @month, :day => @day)
|
45
|
+
(old_date <=> new_date).should == -1
|
46
|
+
(new_date <=> old_date).should == 1
|
47
|
+
(new_date <=> new_date).should == 0
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context "mixed date types" do
|
52
|
+
it "should demonstrate later dates as greater than older dates" do
|
53
|
+
old_date = PseudoDate.new(:year => @year, :month => @month)
|
54
|
+
new_date = PseudoDate.new(:year => 1996, :month => @month, :day => @day)
|
55
|
+
(old_date < new_date).should be_true
|
56
|
+
end
|
57
|
+
it "should demonstrate invalid dates as less than complete dates" do
|
58
|
+
complete = PseudoDate.new(:year => @year, :month => @month)
|
59
|
+
invalid = PseudoDate.new("")
|
60
|
+
(complete > invalid).should be_true
|
61
|
+
end
|
62
|
+
it "should respond properly with the spaceship operator" do
|
63
|
+
old_date = PseudoDate.new(:year => @year, :month => @month)
|
64
|
+
new_date = PseudoDate.new(:year => 1996, :month => @month, :day => @day)
|
65
|
+
(old_date <=> new_date).should == -1
|
66
|
+
(new_date <=> old_date).should == 1
|
67
|
+
(new_date <=> new_date).should == 0
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context "date sorting" do
|
72
|
+
it "should work for mixed date types" do
|
73
|
+
dates = [{ :year => 2011, :month => 5 }, '1985', nil].map { |d| PseudoDate.new(d) }
|
74
|
+
sorted = dates.sort
|
75
|
+
sorted.first.year.should == "0000"
|
76
|
+
sorted.last.year.should == "2011"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context "converting to a hash" do
|
81
|
+
it "should use double digit strings for day and month" do
|
82
|
+
date = PseudoDate.new(:day => '1', :month => '2', :year => '1980')
|
83
|
+
date.to_hash[:day].should == "01"
|
84
|
+
date.to_hash[:month].should == "02"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
metadata
CHANGED
@@ -1,91 +1,81 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: pseudo_date
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.5
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 4
|
10
|
-
version: 0.1.4
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Patrick Tulskie
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
12
|
+
date: 2013-05-01 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
22
30
|
description: Date parser and container for partial or incomplete dates.
|
23
|
-
email:
|
31
|
+
email:
|
32
|
+
- patricktulskie@gmail.com
|
24
33
|
executables: []
|
25
|
-
|
26
34
|
extensions: []
|
27
|
-
|
28
|
-
|
29
|
-
-
|
30
|
-
-
|
31
|
-
-
|
32
|
-
- lib/pseudo_date.rb
|
33
|
-
- lib/pseudo_date/parser.rb
|
34
|
-
- lib/pseudo_date/pseudo_date.rb
|
35
|
-
files:
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- Gemfile
|
39
|
+
- Gemfile.lock
|
36
40
|
- Manifest
|
37
41
|
- README.mdown
|
38
42
|
- Rakefile
|
43
|
+
- benchmark/pseudo_date_benchmark.rb
|
39
44
|
- lib/core_extensions/object.rb
|
40
45
|
- lib/core_extensions/string.rb
|
41
46
|
- lib/pseudo_date.rb
|
42
47
|
- lib/pseudo_date/parser.rb
|
43
48
|
- lib/pseudo_date/pseudo_date.rb
|
49
|
+
- lib/pseudo_date/version.rb
|
44
50
|
- pseudo_date.gemspec
|
45
|
-
-
|
46
|
-
-
|
47
|
-
-
|
48
|
-
has_rdoc: true
|
51
|
+
- spec/parser_spec.rb
|
52
|
+
- spec/pseudo_date_spec.rb
|
53
|
+
- spec/spec_helper.rb
|
49
54
|
homepage: http://github.com/PatrickTulskie/pseudo_date
|
50
55
|
licenses: []
|
51
|
-
|
52
56
|
post_install_message:
|
53
|
-
rdoc_options:
|
54
|
-
|
55
|
-
- --inline-source
|
56
|
-
- --title
|
57
|
-
- Pseudo_date
|
58
|
-
- --main
|
59
|
-
- README.mdown
|
60
|
-
require_paths:
|
57
|
+
rdoc_options: []
|
58
|
+
require_paths:
|
61
59
|
- lib
|
62
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
61
|
none: false
|
64
|
-
requirements:
|
65
|
-
- -
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
|
68
|
-
|
69
|
-
- 0
|
70
|
-
version: "0"
|
71
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
67
|
none: false
|
73
|
-
requirements:
|
74
|
-
- -
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
|
77
|
-
segments:
|
78
|
-
- 1
|
79
|
-
- 2
|
80
|
-
version: "1.2"
|
68
|
+
requirements:
|
69
|
+
- - ! '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
81
72
|
requirements: []
|
82
|
-
|
83
|
-
|
84
|
-
rubygems_version: 1.5.3
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 1.8.24
|
85
75
|
signing_key:
|
86
76
|
specification_version: 3
|
87
77
|
summary: Date parser and container for partial or incomplete dates.
|
88
|
-
test_files:
|
89
|
-
-
|
90
|
-
-
|
91
|
-
-
|
78
|
+
test_files:
|
79
|
+
- spec/parser_spec.rb
|
80
|
+
- spec/pseudo_date_spec.rb
|
81
|
+
- spec/spec_helper.rb
|
data/test/test_parser.rb
DELETED
@@ -1,153 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
-
|
3
|
-
class TestParser < Test::Unit::TestCase
|
4
|
-
|
5
|
-
context "Date formats" 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 "date hash" do
|
15
|
-
should "parse an exact hash" do
|
16
|
-
pd = PseudoDate.new(:year => @year, :day => @day, :month => @month)
|
17
|
-
assert_equal @day, pd.day
|
18
|
-
assert_equal @month, pd.month
|
19
|
-
assert_equal @year, pd.year
|
20
|
-
end
|
21
|
-
|
22
|
-
should "parse a hash inexact keys" do
|
23
|
-
pd = PseudoDate.new('Year' => @year, 'day' => @day, :Month => @month)
|
24
|
-
assert_equal @day, pd.day
|
25
|
-
assert_equal @month, pd.month
|
26
|
-
assert_equal @year, pd.year
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
# 19850625
|
31
|
-
context "yearmonthday" do
|
32
|
-
should 'be exact precision' do
|
33
|
-
assert_equal PseudoDate.new("#{@year}#{@month}#{@day}").precision, 'exact'
|
34
|
-
end
|
35
|
-
|
36
|
-
should 'match original input' do
|
37
|
-
pd = PseudoDate.new("#{@year}#{@month}#{@day}")
|
38
|
-
assert_equal @day, pd.day
|
39
|
-
assert_equal @month, pd.month
|
40
|
-
assert_equal @year, pd.year
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
# 1985-25-06
|
45
|
-
context "year-day-month" do
|
46
|
-
should 'be exact precision' do
|
47
|
-
assert_equal PseudoDate.new("#{@year}-#{@day}-#{@month}").precision, 'exact'
|
48
|
-
end
|
49
|
-
|
50
|
-
should 'match original input' do
|
51
|
-
pd = PseudoDate.new("#{@year}-#{@day}-#{@month}")
|
52
|
-
assert_equal @day, pd.day
|
53
|
-
assert_equal @month, pd.month
|
54
|
-
assert_equal @year, pd.year
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
# 06-25-1985
|
59
|
-
context "month-day-year" do
|
60
|
-
should 'be exact precision' do
|
61
|
-
assert_equal PseudoDate.new("#{@month}-#{@day}-#{@year}").precision, 'exact'
|
62
|
-
end
|
63
|
-
|
64
|
-
should 'match original input' do
|
65
|
-
pd = PseudoDate.new("#{@month}-#{@day}-#{@year}")
|
66
|
-
assert_equal @day, pd.day
|
67
|
-
assert_equal @month, pd.month
|
68
|
-
assert_equal @year, pd.year
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
# 25-06-1985
|
73
|
-
context "day-month-year" do
|
74
|
-
should 'be exact precision' do
|
75
|
-
assert_equal PseudoDate.new("#{@day}-#{@month}-#{@year}").precision, 'exact'
|
76
|
-
end
|
77
|
-
|
78
|
-
should 'match original input' do
|
79
|
-
pd = PseudoDate.new("#{@day}-#{@month}-#{@year}")
|
80
|
-
assert_equal @day, pd.day
|
81
|
-
assert_equal @month, pd.month
|
82
|
-
assert_equal @year, pd.year
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
# 06/25/1985
|
87
|
-
context "month/day/year" do
|
88
|
-
should 'be exact precision' do
|
89
|
-
assert_equal PseudoDate.new("#{@month}/#{@day}/#{@year}").precision, 'exact'
|
90
|
-
end
|
91
|
-
|
92
|
-
should 'match original input' do
|
93
|
-
pd = PseudoDate.new("#{@month}/#{@day}/#{@year}")
|
94
|
-
assert_equal @day, pd.day
|
95
|
-
assert_equal @month, pd.month
|
96
|
-
assert_equal @year, pd.year
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
# 06/1985
|
101
|
-
context "month/year" do
|
102
|
-
should 'be partial precision' do
|
103
|
-
assert_equal PseudoDate.new("#{@month}/#{@year}").precision, 'year_month'
|
104
|
-
end
|
105
|
-
|
106
|
-
should 'match original input' do
|
107
|
-
pd = PseudoDate.new("#{@month}/#{@year}")
|
108
|
-
assert_equal @month, pd.month
|
109
|
-
assert_equal @year, pd.year
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
# 85
|
114
|
-
context "two digit year" do
|
115
|
-
should 'be year precision' do
|
116
|
-
assert_equal PseudoDate.new("85").precision, 'year'
|
117
|
-
end
|
118
|
-
|
119
|
-
should 'match original input' do
|
120
|
-
pd = PseudoDate.new("85")
|
121
|
-
assert_equal @year, pd.year
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
# 1985
|
126
|
-
context "four digit year" do
|
127
|
-
should 'be year precision' do
|
128
|
-
assert_equal PseudoDate.new(@year).precision, 'year'
|
129
|
-
end
|
130
|
-
|
131
|
-
should 'match original input' do
|
132
|
-
pd = PseudoDate.new(@year)
|
133
|
-
assert_equal @year, pd.year
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
# Jun 25, 1985
|
138
|
-
context "string date" do
|
139
|
-
should 'be exact precision' do
|
140
|
-
assert_equal PseudoDate.new(@string_date).precision, 'exact'
|
141
|
-
end
|
142
|
-
|
143
|
-
should 'match original input' do
|
144
|
-
pd = PseudoDate.new(@string_date)
|
145
|
-
assert_equal @day, pd.day
|
146
|
-
assert_equal @month, pd.month
|
147
|
-
assert_equal @year, pd.year
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
end
|
152
|
-
|
153
|
-
end
|
data/test/test_pseudo_date.rb
DELETED
@@ -1,83 +0,0 @@
|
|
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
|