edtf 2.0.0 → 2.1.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.
- checksums.yaml +4 -4
- data/.coveralls.yml +1 -0
- data/.gitignore +2 -1
- data/.simplecov +4 -0
- data/.travis.yml +4 -7
- data/Gemfile +14 -4
- data/README.md +18 -20
- data/Rakefile +14 -4
- data/edtf.gemspec +1 -1
- data/features/support/env.rb +22 -1
- data/lib/edtf/date.rb +65 -58
- data/lib/edtf/date_time.rb +1 -1
- data/lib/edtf/epoch.rb +105 -104
- data/lib/edtf/parser.rb +1793 -0
- data/lib/edtf/season.rb +84 -83
- data/lib/edtf/set.rb +80 -78
- data/lib/edtf/version.rb +1 -1
- data/spec/spec_helper.rb +21 -0
- metadata +28 -20
data/lib/edtf/season.rb
CHANGED
@@ -2,22 +2,22 @@ module EDTF
|
|
2
2
|
|
3
3
|
class Season
|
4
4
|
extend Forwardable
|
5
|
-
|
5
|
+
|
6
6
|
SEASONS = Hash[21, :spring, 22, :summer, 23, :autumn, 24, :winter].freeze
|
7
|
-
|
7
|
+
|
8
8
|
CODES = Hash.new { |h,k| h.fetch(k.to_sym, nil) }.merge(
|
9
9
|
SEASONS.invert).merge({ :fall => 23 }).freeze
|
10
|
-
|
10
|
+
|
11
11
|
NORTHERN = Hash[:spring, [3,4,5], :summer, [6,7,8], :autumn, [9,10,11], :winter, [12,1,2]].freeze
|
12
12
|
SOUTHERN = Hash[:autumn, [3,4,5], :winter, [6,7,8], :spring, [9,10,11], :summer, [12,1,2]].freeze
|
13
|
-
|
13
|
+
|
14
14
|
NORTHERN_MONTHS = Hash[*NORTHERN.map { |s,ms| ms.map { |m| [m,s] } }.flatten].freeze
|
15
15
|
SOUTHERN_MONTHS = Hash[*SOUTHERN.map { |s,ms| ms.map { |m| [m,s] } }.flatten].freeze
|
16
|
-
|
17
|
-
|
16
|
+
|
17
|
+
|
18
18
|
include Comparable
|
19
19
|
include Enumerable
|
20
|
-
|
20
|
+
|
21
21
|
class << self
|
22
22
|
def current
|
23
23
|
Date.today.season
|
@@ -25,20 +25,21 @@ module EDTF
|
|
25
25
|
end
|
26
26
|
|
27
27
|
attr_reader :season, :year
|
28
|
-
|
28
|
+
|
29
29
|
attr_accessor :qualifier, :uncertain, :approximate
|
30
|
-
|
31
|
-
def_delegators :to_range,
|
32
|
-
|
33
|
-
|
30
|
+
|
31
|
+
def_delegators :to_range, *Range.instance_methods(false).reject { |m|
|
32
|
+
m.to_s =~ /^(each|min|max|cover\?|inspect|to_s)$|^\W/
|
33
|
+
}
|
34
|
+
|
34
35
|
SEASONS.each_value do |s|
|
35
36
|
define_method("#{s}?") { @season == s }
|
36
37
|
define_method("#{s}!") { @season = s }
|
37
38
|
end
|
38
|
-
|
39
|
+
|
39
40
|
alias fall? autumn?
|
40
41
|
alias fall! autumn!
|
41
|
-
|
42
|
+
|
42
43
|
[:first, :second, :third, :fourth].zip([:spring, :summer, :autumn, :winter]).each do |quarter, season|
|
43
44
|
alias_method("#{quarter}?", "#{season}?")
|
44
45
|
alias_method("#{quarter}!", "#{season}!")
|
@@ -48,7 +49,7 @@ module EDTF
|
|
48
49
|
def initialize(*arguments)
|
49
50
|
arguments.flatten!
|
50
51
|
raise ArgumentError, "wrong number of arguments (#{arguments.length} for 0..3)" if arguments.length > 3
|
51
|
-
|
52
|
+
|
52
53
|
if arguments.length == 1
|
53
54
|
case arguments[0]
|
54
55
|
when Date
|
@@ -67,45 +68,45 @@ module EDTF
|
|
67
68
|
end
|
68
69
|
|
69
70
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
71
|
+
[:uncertain, :approximate].each do |m|
|
72
|
+
|
73
|
+
define_method("#{m}?") { !!send(m) }
|
74
|
+
|
75
|
+
define_method("#{m}!") do
|
76
|
+
send("#{m}=", true)
|
77
|
+
self
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def certain?; !uncertain; end
|
82
|
+
def precise?; !approximate; end
|
83
|
+
|
84
|
+
def certain!
|
85
|
+
@uncertain = false
|
86
|
+
self
|
87
|
+
end
|
88
|
+
|
89
|
+
def precise!
|
90
|
+
@approximate = false
|
91
|
+
end
|
92
|
+
|
93
|
+
# Returns the next season.
|
94
|
+
def succ
|
95
|
+
s = dup
|
96
|
+
s.season = next_season_code
|
97
|
+
s.year = year + 1 if s.first?
|
98
|
+
s
|
99
|
+
end
|
100
|
+
|
101
|
+
# def next(n = 1)
|
102
|
+
# end
|
103
|
+
|
104
|
+
def cover?(other)
|
105
|
+
return false unless other.respond_to?(:day_precision)
|
106
|
+
other = other.day_precision
|
107
|
+
min.day_precision! <= other && other <= max.day_precision!
|
108
|
+
end
|
109
|
+
|
109
110
|
def each
|
110
111
|
if block_given?
|
111
112
|
to_range.each(&Proc.new)
|
@@ -114,33 +115,33 @@ module EDTF
|
|
114
115
|
to_enum
|
115
116
|
end
|
116
117
|
end
|
117
|
-
|
118
|
+
|
118
119
|
def year=(new_year)
|
119
120
|
@year = new_year.to_i
|
120
121
|
end
|
121
|
-
|
122
|
+
|
122
123
|
def season=(new_season)
|
123
124
|
@season = SEASONS[new_season] || SEASONS[CODES[new_season]] ||
|
124
125
|
raise(ArgumentError, "unknown season/format: #{new_season.inspect})")
|
125
126
|
end
|
126
127
|
|
127
128
|
def season?; true; end
|
128
|
-
|
129
|
+
|
129
130
|
def qualified?; !!@qualifier; end
|
130
|
-
|
131
|
+
|
131
132
|
def edtf
|
132
133
|
'%04d-%2d%s' % [year, CODES[season], qualified? ? "^#{qualifier}" : '']
|
133
134
|
end
|
134
135
|
|
135
136
|
alias to_s edtf
|
136
137
|
|
137
|
-
|
138
|
+
|
138
139
|
def <=>(other)
|
139
140
|
case other
|
140
141
|
when Date
|
141
142
|
cover?(other) ? 0 : to_date <=> other
|
142
|
-
|
143
|
-
|
143
|
+
when Interval, Epoch
|
144
|
+
[min, max] <=> [other.min, other.max]
|
144
145
|
when Season
|
145
146
|
[year, month, qualifier] <=> [other.year, other.month, other.qualifier]
|
146
147
|
else
|
@@ -149,42 +150,42 @@ module EDTF
|
|
149
150
|
rescue
|
150
151
|
nil
|
151
152
|
end
|
152
|
-
|
153
|
+
|
153
154
|
def ===(other)
|
154
155
|
(self <=> other) == 0
|
155
156
|
rescue
|
156
157
|
false
|
157
158
|
end
|
158
|
-
|
159
|
+
|
159
160
|
def to_date
|
160
161
|
Date.new(year, month, 1)
|
161
162
|
end
|
162
163
|
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
164
|
+
alias min to_date
|
165
|
+
|
166
|
+
def max
|
167
|
+
to_date.months_since(2).end_of_month
|
168
|
+
end
|
169
|
+
|
169
170
|
# Returns a Range that covers the season (a three month period).
|
170
171
|
def to_range
|
171
|
-
|
172
|
+
min .. max
|
172
173
|
end
|
173
|
-
|
174
|
+
|
174
175
|
protected
|
175
|
-
|
176
|
+
|
176
177
|
def month
|
177
178
|
NORTHERN[@season][0]
|
178
179
|
end
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
180
|
+
|
181
|
+
def season_code
|
182
|
+
CODES[season]
|
183
|
+
end
|
184
|
+
|
185
|
+
def next_season_code(by = 1)
|
186
|
+
((season_code + by) % 4) + 20
|
187
|
+
end
|
188
|
+
|
188
189
|
end
|
189
|
-
|
190
|
-
end
|
190
|
+
|
191
|
+
end
|
data/lib/edtf/set.rb
CHANGED
@@ -1,79 +1,81 @@
|
|
1
1
|
module EDTF
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
end
|
2
|
+
|
3
|
+
class Set
|
4
|
+
extend Forwardable
|
5
|
+
|
6
|
+
include Enumerable
|
7
|
+
include Comparable
|
8
|
+
|
9
|
+
def_delegators :@dates, :size, :length, :empty?
|
10
|
+
def_delegators :to_a, :include?
|
11
|
+
|
12
|
+
attr_accessor :choice, :later, :earlier
|
13
|
+
|
14
|
+
|
15
|
+
def initialize(*dates)
|
16
|
+
@dates = ::Set.new(dates.flatten)
|
17
|
+
@choice, @later, @earlier = false, false, false
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize_copy(other)
|
21
|
+
@set = other.to_set
|
22
|
+
end
|
23
|
+
|
24
|
+
[:choice, :later, :earlier].each do |m|
|
25
|
+
define_method("#{m}?") { send(m) }
|
26
|
+
define_method("#{m}!") do
|
27
|
+
send("#{m}=", true)
|
28
|
+
self
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def <<(date)
|
33
|
+
dates << date
|
34
|
+
self
|
35
|
+
end
|
36
|
+
|
37
|
+
def each
|
38
|
+
if block_given?
|
39
|
+
to_a.each(&Proc.new)
|
40
|
+
self
|
41
|
+
else
|
42
|
+
to_enum
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def edtf
|
47
|
+
parenthesize(dates.map { |d| d.respond_to?(:edtf) ? d.edtf : d.to_s }.sort.join(', '))
|
48
|
+
end
|
49
|
+
|
50
|
+
def to_a
|
51
|
+
dates.map { |d| Array(d) }.flatten.sort
|
52
|
+
end
|
53
|
+
|
54
|
+
def to_set
|
55
|
+
to_a.to_set
|
56
|
+
end
|
57
|
+
|
58
|
+
alias to_s edtf
|
59
|
+
|
60
|
+
def <=>(other)
|
61
|
+
return nil unless other.respond_to?(:to_a)
|
62
|
+
to_a <=> other.to_a
|
63
|
+
end
|
64
|
+
|
65
|
+
protected
|
66
|
+
|
67
|
+
attr_reader :dates
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def parenthesize(string)
|
72
|
+
p = choice? ? %w([ ]) : %w({ })
|
73
|
+
p[-1,0] = '..' if earlier?
|
74
|
+
p[-1,0] = string unless string.empty?
|
75
|
+
p[-1,0] = '..' if later?
|
76
|
+
p.join
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
data/lib/edtf/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,24 @@
|
|
1
|
+
begin
|
2
|
+
require 'simplecov'
|
3
|
+
require 'coveralls' if ENV['CI']
|
4
|
+
rescue LoadError
|
5
|
+
# ignore
|
6
|
+
end
|
7
|
+
|
8
|
+
begin
|
9
|
+
case
|
10
|
+
when RUBY_PLATFORM < 'java'
|
11
|
+
require 'debug'
|
12
|
+
Debugger.start
|
13
|
+
when defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
|
14
|
+
require 'rubinius/debugger'
|
15
|
+
else
|
16
|
+
require 'debugger'
|
17
|
+
end
|
18
|
+
rescue LoadError
|
19
|
+
# ignore
|
20
|
+
end
|
21
|
+
|
1
22
|
$LOAD_PATH << File.expand_path('../../lib', __FILE__)
|
2
23
|
|
3
24
|
require 'edtf'
|
metadata
CHANGED
@@ -1,29 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: edtf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sylvester Keil
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '3.0'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '5.0'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- -
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.0'
|
30
|
+
- - "<"
|
25
31
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
32
|
+
version: '5.0'
|
27
33
|
description: A Ruby implementation of the Extended Date/Time Format (EDTF).
|
28
34
|
email:
|
29
35
|
- http://sylvester.keil.or.at
|
@@ -33,10 +39,12 @@ extra_rdoc_files:
|
|
33
39
|
- README.md
|
34
40
|
- LICENSE
|
35
41
|
files:
|
36
|
-
- .autotest
|
37
|
-
- .
|
38
|
-
- .
|
39
|
-
- .
|
42
|
+
- ".autotest"
|
43
|
+
- ".coveralls.yml"
|
44
|
+
- ".gitignore"
|
45
|
+
- ".rspec"
|
46
|
+
- ".simplecov"
|
47
|
+
- ".travis.yml"
|
40
48
|
- Gemfile
|
41
49
|
- LICENSE
|
42
50
|
- README.md
|
@@ -62,6 +70,7 @@ files:
|
|
62
70
|
- lib/edtf/epoch.rb
|
63
71
|
- lib/edtf/extensions.rb
|
64
72
|
- lib/edtf/interval.rb
|
73
|
+
- lib/edtf/parser.rb
|
65
74
|
- lib/edtf/parser.y
|
66
75
|
- lib/edtf/season.rb
|
67
76
|
- lib/edtf/set.rb
|
@@ -75,35 +84,34 @@ files:
|
|
75
84
|
- spec/edtf/set_spec.rb
|
76
85
|
- spec/edtf/uncertainty_spec.rb
|
77
86
|
- spec/spec_helper.rb
|
78
|
-
- lib/edtf/parser.rb
|
79
87
|
homepage: http://github.com/inukshuk/edtf-ruby
|
80
88
|
licenses:
|
81
89
|
- FreeBSD
|
82
90
|
metadata: {}
|
83
91
|
post_install_message:
|
84
92
|
rdoc_options:
|
85
|
-
- --line-numbers
|
86
|
-
- --inline-source
|
87
|
-
- --title
|
88
|
-
-
|
89
|
-
- --main
|
93
|
+
- "--line-numbers"
|
94
|
+
- "--inline-source"
|
95
|
+
- "--title"
|
96
|
+
- "\"EDTF-Ruby\""
|
97
|
+
- "--main"
|
90
98
|
- README.md
|
91
|
-
- --webcvs=http://github.com/inukshuk/edtf-ruby/tree/master/
|
99
|
+
- "--webcvs=http://github.com/inukshuk/edtf-ruby/tree/master/"
|
92
100
|
require_paths:
|
93
101
|
- lib
|
94
102
|
required_ruby_version: !ruby/object:Gem::Requirement
|
95
103
|
requirements:
|
96
|
-
- -
|
104
|
+
- - ">="
|
97
105
|
- !ruby/object:Gem::Version
|
98
106
|
version: '0'
|
99
107
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
108
|
requirements:
|
101
|
-
- -
|
109
|
+
- - ">="
|
102
110
|
- !ruby/object:Gem::Version
|
103
111
|
version: '0'
|
104
112
|
requirements: []
|
105
113
|
rubyforge_project:
|
106
|
-
rubygems_version: 2.1
|
114
|
+
rubygems_version: 2.2.1
|
107
115
|
signing_key:
|
108
116
|
specification_version: 4
|
109
117
|
summary: Extended Date/Time Format for Ruby.
|