edtf 4.1.1 → 5.0.0

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.
@@ -1,100 +0,0 @@
1
- module EDTF
2
-
3
- # TODO use bitmasks instead of arrays
4
-
5
- class Uncertainty < Struct.new(:year, :month, :day)
6
-
7
- attr_reader :hash_base
8
-
9
- def initialize(year = nil, month = nil, day = nil, hash_base = 1)
10
- @hash_base = hash_base
11
- super(year, month, day)
12
- end
13
-
14
- def hash_base=(base)
15
- @hash_base = base
16
- end
17
-
18
- def uncertain?(parts = members)
19
- [*parts].any? { |p| !!send(p) }
20
- end
21
-
22
- def uncertain!(parts = members)
23
- [*parts].each { |p| send("#{p}=", true) }
24
- self
25
- end
26
-
27
- def certain?(parts = members); !uncertain?(parts); end
28
-
29
- def certain!(parts = members)
30
- [*parts].each { |p| send("#{p}=", false) }
31
- self
32
- end
33
-
34
- def eql?(other)
35
- hash == other.hash
36
- end
37
-
38
- def hash
39
- (year ? hash_base : 0) + (month ? hash_base << 1 : 0) + (day ? hash_base << 2 : 0)
40
- end
41
-
42
- end
43
-
44
-
45
- class Unspecified < Struct.new(:year, :month, :day)
46
-
47
- X = 'X'.freeze
48
-
49
- def initialize
50
- super Array.new(4),Array.new(2), Array.new(2)
51
- end
52
-
53
- def unspecified?(parts = members)
54
- [*parts].any? { |p| send(p).any? { |u| !!u } }
55
- end
56
-
57
- def unspecified!(parts = members)
58
- [*parts].each { |p| send(p).map! { true } }
59
- self
60
- end
61
-
62
- def specified?(parts = members); !unspecified?(parts); end
63
-
64
- def specified!(parts = members)
65
- [*parts].each { |p| send(p).map! { false } }
66
- self
67
- end
68
-
69
- alias specific? specified?
70
- alias unspecific? unspecified?
71
-
72
- alias specific! specified!
73
- alias unspecific! unspecified!
74
-
75
- def hash
76
- y, m, d = year, month, day
77
- (y[0] ? 1 : 0) | (y[1] ? 2 : 0) | (y[2] ? 4 : 0) | (y[3] ? 8 : 0) |
78
- (m[0] ? 16 : 0) | (m[1] ? 32 : 0) | (d[0] ? 64 : 0) | (d[1] ? 128 : 0)
79
- end
80
-
81
- private :year=, :month=, :day=
82
-
83
- def to_s
84
- mask(%w{ ssss ss ss }).join('-')
85
- end
86
-
87
- def mask(values)
88
- if values[0] && values[0][0] == "-"
89
- values[0].delete!("-")
90
- negative_year = true
91
- end
92
- results = values.zip(members.take(values.length)).map do |value, mask|
93
- value.split(//).zip(send(mask)).map { |v,m| m ? X : v }.join
94
- end
95
- results[0] = "-#{results[0]}" if negative_year
96
- results
97
- end
98
- end
99
-
100
- end
data/lib/edtf/unknown.rb DELETED
@@ -1,25 +0,0 @@
1
- module EDTF
2
- class Unknown < ::Date::Infinity
3
- def edtf
4
- 'uuuu'
5
- end
6
-
7
- alias to_s edtf
8
-
9
- def uncertain?
10
- true
11
- end
12
-
13
- def certain?
14
- false
15
- end
16
-
17
- def approximate?
18
- true
19
- end
20
-
21
- def precise?
22
- false
23
- end
24
- end
25
- end