edtf 0.0.1
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 +3 -0
- data/.rspec +3 -0
- data/Gemfile +7 -0
- data/LICENSE +26 -0
- data/README.md +81 -0
- data/Rakefile +21 -0
- data/edtf.gemspec +34 -0
- data/features/parser/date_times.feature +35 -0
- data/features/parser/dates.feature +53 -0
- data/features/parser/intervals.feature +19 -0
- data/features/parser/precision.feature +14 -0
- data/features/parser/unspecified.feature +19 -0
- data/features/step_definitions/edtf_steps.rb +80 -0
- data/features/support/env.rb +1 -0
- data/lib/edtf.rb +35 -0
- data/lib/edtf/date.rb +77 -0
- data/lib/edtf/extensions.rb +4 -0
- data/lib/edtf/interval.rb +66 -0
- data/lib/edtf/parser.y +313 -0
- data/lib/edtf/seasons.rb +36 -0
- data/lib/edtf/uncertainty.rb +58 -0
- data/lib/edtf/version.rb +3 -0
- data/spec/edtf/extensions_spec.rb +44 -0
- data/spec/edtf/seasons_spec.rb +59 -0
- data/spec/edtf/uncertainty_spec.rb +114 -0
- data/spec/spec_helper.rb +8 -0
- metadata +148 -0
data/lib/edtf/seasons.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
module EDTF
|
2
|
+
|
3
|
+
module Seasons
|
4
|
+
|
5
|
+
attr_reader :season
|
6
|
+
|
7
|
+
def season?; !!@season; end
|
8
|
+
|
9
|
+
def season=(new_season)
|
10
|
+
case new_season
|
11
|
+
when 1, 2, 3, 4
|
12
|
+
@season = new_season + 20
|
13
|
+
when 21, 22, 23, 24
|
14
|
+
@season = new_season
|
15
|
+
else
|
16
|
+
raise ArgumentError, "bad season format (21, 22, 23 or 24 expected; was #{new_season.inspect})"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
[:first, :second, :third, :fourth].zip(21..24).each do |quarter, code|
|
21
|
+
define_method("#{quarter}?") { @season == code }
|
22
|
+
define_method("#{quarter}!") { @season = code }
|
23
|
+
end
|
24
|
+
|
25
|
+
[:spring, :summer, :autumn, :winter].zip([:first, :second, :third, :fourth]).each do |season, quarter|
|
26
|
+
alias_method("#{season}?", "#{quarter}?")
|
27
|
+
alias_method("#{season}!", "#{quarter}!")
|
28
|
+
end
|
29
|
+
|
30
|
+
attr_accessor :qualifier
|
31
|
+
|
32
|
+
def qualified?; !!@qualifier; end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module EDTF
|
2
|
+
|
3
|
+
class Uncertainty < Struct.new(:year, :month, :day, :hour, :minute, :second)
|
4
|
+
def uncertain?(parts = members)
|
5
|
+
[parts].flatten.any? { |p| !!send(p) }
|
6
|
+
end
|
7
|
+
|
8
|
+
def uncertain!(parts = members)
|
9
|
+
[parts].flatten.each { |p| send("#{p}=", true) }
|
10
|
+
self
|
11
|
+
end
|
12
|
+
|
13
|
+
def certain?(parts = members); !uncertain?(parts); end
|
14
|
+
|
15
|
+
def certain!(parts = members)
|
16
|
+
[parts].flatten.each { |p| send("#{p}=", false) }
|
17
|
+
self
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# year = []
|
22
|
+
class Unspecified < Struct.new(:year, :month, :day)
|
23
|
+
|
24
|
+
def initialize
|
25
|
+
super year = Array.new(4), month = Array.new(2), day = Array.new(2)
|
26
|
+
end
|
27
|
+
|
28
|
+
def unspecified?(parts = members)
|
29
|
+
[parts].flatten.any? { |p| send(p).any? { |u| !!u } }
|
30
|
+
end
|
31
|
+
|
32
|
+
def unspecified!(parts = members)
|
33
|
+
[parts].flatten.each { |p| send(p).map! { true } }
|
34
|
+
self
|
35
|
+
end
|
36
|
+
|
37
|
+
def specified?(parts = members); !unspecified?(parts); end
|
38
|
+
|
39
|
+
def specified!(parts = members)
|
40
|
+
[parts].flatten.each { |p| send(p).map! { false } }
|
41
|
+
self
|
42
|
+
end
|
43
|
+
|
44
|
+
alias specific? specified?
|
45
|
+
alias unspecific? unspecified?
|
46
|
+
|
47
|
+
alias specific! specified!
|
48
|
+
alias unspecific! unspecified!
|
49
|
+
|
50
|
+
private :year=, :month=, :day=
|
51
|
+
|
52
|
+
def to_s
|
53
|
+
[year, month, day].map { |p| p.map { |i| i ? 'u' : 's' }.join }.join('-')
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
data/lib/edtf/version.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
describe DateTime do
|
2
|
+
|
3
|
+
let(:date) { DateTime.new }
|
4
|
+
|
5
|
+
describe 'class methods' do
|
6
|
+
it 'responds to edtf' do
|
7
|
+
DateTime.respond_to?(:edtf).should == true
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'instance methods' do
|
12
|
+
[:uncertain?, :approximate?, :unspecified?, :uncertain, :approximate, :unspecified].each do |method|
|
13
|
+
it "responds to #{method}" do
|
14
|
+
DateTime.new.respond_to?(method).should == true
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#uncertain?' do
|
20
|
+
|
21
|
+
it { should_not be_uncertain }
|
22
|
+
|
23
|
+
[:year, :month, :day].each do |part|
|
24
|
+
it "should not be uncertain by default (#{part})" do
|
25
|
+
DateTime.new.uncertain?(part).should == false
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should be uncertain if set to uncertain (#{part})" do
|
29
|
+
date.uncertain.send("#{part}=", true)
|
30
|
+
date.uncertain?(part).should == true
|
31
|
+
end
|
32
|
+
|
33
|
+
([:year, :month, :day] - [part]).each do |other|
|
34
|
+
it "#{other} should not be uncertain if #{part} is uncertain" do
|
35
|
+
date.uncertain.send("#{part}=", true)
|
36
|
+
date.uncertain?(other).should == false
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module EDTF
|
2
|
+
describe 'Seasons' do
|
3
|
+
let(:subject) { Date.new }
|
4
|
+
|
5
|
+
describe '#season?' do
|
6
|
+
it 'returns false by default' do
|
7
|
+
subject.should_not be_season
|
8
|
+
end
|
9
|
+
|
10
|
+
context 'when a season code is set' do
|
11
|
+
before(:all) { subject.season = 21 }
|
12
|
+
it 'returns true if a season code is set' do
|
13
|
+
subject.should be_season
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#season' do
|
19
|
+
before(:each) { subject.season = 21 }
|
20
|
+
|
21
|
+
it 'returns the season code' do
|
22
|
+
subject.season.should == 21
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#season=' do
|
27
|
+
it 'sets the season code when called with a valid season code' do
|
28
|
+
lambda do
|
29
|
+
(21..22).each do |i|
|
30
|
+
subject.season = i
|
31
|
+
end
|
32
|
+
end.should_not raise_error
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'throws an exception if given invalid season code' do
|
36
|
+
lambda { subject.season = 13 }.should raise_error
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#winter!' do
|
41
|
+
it 'sets the season code to 24' do
|
42
|
+
lambda { subject.winter! }.should change { subject.season }.to(24)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#winter?' do
|
47
|
+
it 'returns true if the season code is 24' do
|
48
|
+
subject.season = 24
|
49
|
+
subject.should be_winter
|
50
|
+
end
|
51
|
+
it 'returns false if the season code is not 24' do
|
52
|
+
subject.season = 23
|
53
|
+
subject.should_not be_winter
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
module EDTF
|
2
|
+
|
3
|
+
describe Uncertainty do
|
4
|
+
|
5
|
+
let(:uncertainty) { Uncertainty.new }
|
6
|
+
|
7
|
+
describe '#uncertain?' do
|
8
|
+
|
9
|
+
it { should be_certain }
|
10
|
+
|
11
|
+
it 'should be uncertain if at least one part is uncertain' do
|
12
|
+
Uncertainty.new(false, false, true).should be_uncertain
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should not be uncertain if all parts are certain' do
|
16
|
+
Uncertainty.new(false, false, false, false, false, false).should be_certain
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should be uncertain if all parts are uncertain' do
|
20
|
+
Uncertainty.new(true, true, true, true, true, true).should be_uncertain
|
21
|
+
end
|
22
|
+
|
23
|
+
[:year, :month, :day, :hour, :minute, :second].each do |part|
|
24
|
+
it "#{ part } should not be uncertain by default" do
|
25
|
+
uncertainty.uncertain?(part).should be false
|
26
|
+
end
|
27
|
+
|
28
|
+
it "#{ part } should be uncertain if set to uncertain" do
|
29
|
+
uncertainty.send("#{part}=", true)
|
30
|
+
uncertainty.uncertain?(part).should be true
|
31
|
+
end
|
32
|
+
|
33
|
+
([:year, :month, :day, :hour, :minute, :second] - [part]).each do |other|
|
34
|
+
it "#{other} should not be uncertain if #{part} is uncertain" do
|
35
|
+
uncertainty.send("#{part}=", true)
|
36
|
+
uncertainty.uncertain?(other).should be false
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#uncertain!' do
|
45
|
+
it 'should make all parts certain when no part given' do
|
46
|
+
lambda { uncertainty.uncertain! }.should change { uncertainty.certain? }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
describe Unspecified do
|
53
|
+
let(:u) { Unspecified.new }
|
54
|
+
|
55
|
+
|
56
|
+
describe '#unspecified?' do
|
57
|
+
it 'should return false by default' do
|
58
|
+
u.should_not be_unspecified
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should return true if the day is unspecified' do
|
62
|
+
u.unspecified!(:day).should be_unspecified
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'should return true if the month is unspecified' do
|
66
|
+
u.unspecified!(:month).should be_unspecified
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'should return true if the year is unspecified' do
|
70
|
+
u.unspecified!(:year).should be_unspecified
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '#year' do
|
75
|
+
it 'returns the year values' do
|
76
|
+
u.year.should == [nil,nil,nil,nil]
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'allows you to set individual offsets' do
|
80
|
+
u.year[1] = true
|
81
|
+
u.to_s.should == 'suss-ss-ss'
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe '#to_s' do
|
86
|
+
it 'should be return "ssss-ss-ss" by default' do
|
87
|
+
u.to_s.should == 'ssss-ss-ss'
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'should return "ssss-ss-uu" if the day is unspecified' do
|
91
|
+
u.unspecified!(:day).to_s.should == 'ssss-ss-uu'
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'should return "ssss-uu-ss" if the month is unspecified' do
|
95
|
+
u.unspecified!(:month).to_s.should == 'ssss-uu-ss'
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'should return "ssss-uu-uu" if month and day are unspecified' do
|
99
|
+
u.unspecified!([:day, :month]).to_s.should == 'ssss-uu-uu'
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'should return "uuuu-ss-ss" if the year is unspecified' do
|
103
|
+
u.unspecified!(:year).to_s.should == 'uuuu-ss-ss'
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'should return "uuuu-uu-uu" if the date is unspecified' do
|
107
|
+
u.unspecified!.to_s.should == 'uuuu-uu-uu'
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: edtf
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Sylvester Keil
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-08-14 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: &2156252420 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0.9'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2156252420
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: racc
|
27
|
+
requirement: &2156251780 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '1.4'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2156251780
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: cucumber
|
38
|
+
requirement: &2156251180 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '1.0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *2156251180
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec
|
49
|
+
requirement: &2156250520 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.6'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *2156250520
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: ZenTest
|
60
|
+
requirement: &2156249940 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ~>
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '4.6'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *2156249940
|
69
|
+
description: An Extended Date/Time Format (EDTF) Parser for Ruby.
|
70
|
+
email:
|
71
|
+
- http://sylvester.keil.or.at
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files:
|
75
|
+
- README.md
|
76
|
+
- LICENSE
|
77
|
+
files:
|
78
|
+
- .gitignore
|
79
|
+
- .rspec
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- edtf.gemspec
|
85
|
+
- features/parser/date_times.feature
|
86
|
+
- features/parser/dates.feature
|
87
|
+
- features/parser/intervals.feature
|
88
|
+
- features/parser/precision.feature
|
89
|
+
- features/parser/unspecified.feature
|
90
|
+
- features/step_definitions/edtf_steps.rb
|
91
|
+
- features/support/env.rb
|
92
|
+
- lib/edtf.rb
|
93
|
+
- lib/edtf/date.rb
|
94
|
+
- lib/edtf/extensions.rb
|
95
|
+
- lib/edtf/interval.rb
|
96
|
+
- lib/edtf/parser.y
|
97
|
+
- lib/edtf/seasons.rb
|
98
|
+
- lib/edtf/uncertainty.rb
|
99
|
+
- lib/edtf/version.rb
|
100
|
+
- spec/edtf/extensions_spec.rb
|
101
|
+
- spec/edtf/seasons_spec.rb
|
102
|
+
- spec/edtf/uncertainty_spec.rb
|
103
|
+
- spec/spec_helper.rb
|
104
|
+
- lib/edtf/parser.rb
|
105
|
+
homepage: http://inukshuk.github.com/edtf-ruby
|
106
|
+
licenses:
|
107
|
+
- FreeBSD
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options:
|
110
|
+
- --line-numbers
|
111
|
+
- --inline-source
|
112
|
+
- --title
|
113
|
+
- ! '"EDTF-Ruby"'
|
114
|
+
- --main
|
115
|
+
- README.md
|
116
|
+
- --webcvs=http://github.com/inukshuk/edtf-ruby/tree/master/
|
117
|
+
require_paths:
|
118
|
+
- lib
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
none: false
|
121
|
+
requirements:
|
122
|
+
- - ! '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
+
none: false
|
127
|
+
requirements:
|
128
|
+
- - ! '>='
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
requirements: []
|
132
|
+
rubyforge_project:
|
133
|
+
rubygems_version: 1.8.7
|
134
|
+
signing_key:
|
135
|
+
specification_version: 3
|
136
|
+
summary: Extended Date/Time Format for Ruby.
|
137
|
+
test_files:
|
138
|
+
- features/parser/date_times.feature
|
139
|
+
- features/parser/dates.feature
|
140
|
+
- features/parser/intervals.feature
|
141
|
+
- features/parser/precision.feature
|
142
|
+
- features/parser/unspecified.feature
|
143
|
+
- features/step_definitions/edtf_steps.rb
|
144
|
+
- features/support/env.rb
|
145
|
+
- spec/edtf/extensions_spec.rb
|
146
|
+
- spec/edtf/seasons_spec.rb
|
147
|
+
- spec/edtf/uncertainty_spec.rb
|
148
|
+
- spec/spec_helper.rb
|