edtf 0.0.2 → 0.0.3
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/.autotest +8 -0
- data/.gitignore +1 -0
- data/README.md +6 -3
- data/lib/edtf/compatibility.rb +2 -2
- data/lib/edtf/date.rb +64 -1
- data/lib/edtf/date_time.rb +15 -0
- data/lib/edtf/extensions.rb +4 -0
- data/lib/edtf/parser.rb +754 -457
- data/lib/edtf/parser.y +72 -17
- data/lib/edtf/version.rb +1 -1
- data/lib/edtf.rb +1 -0
- data/spec/edtf/parser_spec.rb +171 -0
- metadata +15 -13
- data/spec/edtf/extensions_spec.rb +0 -44
data/.autotest
ADDED
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -12,10 +12,13 @@ As of EDTF Specification DRAFT, August 4, 2001:
|
|
12
12
|
|
13
13
|
* Level 0: fully implemented
|
14
14
|
* Level 1: fully implemented
|
15
|
-
* Level 2: implemented features 204, 207, 208, and 209
|
15
|
+
* Level 2: implemented features 202, 203, 204, 2041, 207, 208, and 209
|
16
16
|
|
17
|
-
The
|
18
|
-
|
17
|
+
The level 2 list extensions (203 and 204) currently return simple Ruby arrays;
|
18
|
+
therefore, advanced behavior (such as 'earlier' or 'later') is parsed correctly
|
19
|
+
but not yet exposed by the Ruby API.
|
20
|
+
|
21
|
+
The level 2 extensions 201 and 205 are currently _not_ supported.
|
19
22
|
|
20
23
|
EDTF-Ruby has been confirmed to work on the following Ruby implementations:
|
21
24
|
1.9.2, 1.8.7, rbx, jruby.
|
data/lib/edtf/compatibility.rb
CHANGED
data/lib/edtf/date.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
module EDTF
|
2
2
|
|
3
|
+
PRECISIONS = [:year, :month, :day].freeze
|
4
|
+
|
3
5
|
module ExtendedDate
|
4
6
|
|
5
7
|
extend Forwardable
|
@@ -8,6 +10,14 @@ module EDTF
|
|
8
10
|
|
9
11
|
attr_accessor :calendar
|
10
12
|
|
13
|
+
attr_reader :precision
|
14
|
+
|
15
|
+
def precision=(precision)
|
16
|
+
raise ArgumentError, "invalid precision #{precision.inspect}" unless PRECISIONS.include?(precision.to_sym)
|
17
|
+
@precision = precision.to_sym
|
18
|
+
update_precision_filter[-1]
|
19
|
+
end
|
20
|
+
|
11
21
|
def self.included(base)
|
12
22
|
base.extend(ClassMethods)
|
13
23
|
end
|
@@ -40,16 +50,28 @@ module EDTF
|
|
40
50
|
approximate.uncertain?(*arguments)
|
41
51
|
end
|
42
52
|
|
53
|
+
alias approximately? approximate?
|
54
|
+
|
43
55
|
def approximate!(*arguments)
|
44
56
|
approximate.uncertain!(*arguments)
|
45
57
|
self
|
46
58
|
end
|
47
59
|
|
60
|
+
alias approximately! approximate!
|
61
|
+
|
62
|
+
def precise?(*arguments)
|
63
|
+
!approximate?(*arguments)
|
64
|
+
end
|
65
|
+
|
66
|
+
alias precisely? precise?
|
67
|
+
|
48
68
|
def precise!(*arguments)
|
49
69
|
approximate.certain!(*arguments)
|
50
70
|
self
|
51
71
|
end
|
52
72
|
|
73
|
+
alias precisely! precise!
|
74
|
+
|
53
75
|
def_delegators :unspecified, :unspecified?, :specified?, :unsepcific?, :specific?
|
54
76
|
|
55
77
|
def unspecified!(*arguments)
|
@@ -65,7 +87,48 @@ module EDTF
|
|
65
87
|
end
|
66
88
|
|
67
89
|
alias specific! specified!
|
68
|
-
|
90
|
+
|
91
|
+
def to_edtf
|
92
|
+
"TODO"
|
93
|
+
end
|
94
|
+
|
95
|
+
# TODO take precision into account
|
96
|
+
def next
|
97
|
+
super
|
98
|
+
end
|
99
|
+
|
100
|
+
def values
|
101
|
+
precision_filter.map { |p| send(p) }
|
102
|
+
end
|
103
|
+
|
104
|
+
# Returns the same date with negated year
|
105
|
+
def negate
|
106
|
+
v = values
|
107
|
+
y = -1 * v.shift
|
108
|
+
self.class.new(y, *v) # TODO copy extended attributes
|
109
|
+
end
|
110
|
+
|
111
|
+
alias -@ negate
|
112
|
+
|
113
|
+
|
114
|
+
private
|
115
|
+
|
116
|
+
def precision_filter
|
117
|
+
@precision_filter ||= update_precision_filter
|
118
|
+
end
|
119
|
+
|
120
|
+
def update_precision_filter
|
121
|
+
case @precision
|
122
|
+
when :year
|
123
|
+
[:year]
|
124
|
+
when :month
|
125
|
+
[:year,:month]
|
126
|
+
else
|
127
|
+
[:year,:month,:day]
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
|
69
132
|
module ClassMethods
|
70
133
|
def edtf(input, options = {})
|
71
134
|
::EDTF::Parser.new(options).parse(input)
|