historical_dating 1.1.0 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +20 -20
- data/README.md +2 -3
- data/historical_dating.gemspec +1 -1
- data/lib/historical_dating.rb +1 -0
- data/lib/historical_dating/api.rb +1 -1
- data/lib/historical_dating/parser.rb +123 -27
- data/lib/historical_dating/pre_transform.rb +66 -0
- data/lib/historical_dating/transform.rb +25 -6
- data/lib/historical_dating/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a00cb6bc3975511c1024df18f2aeaefe6fd0b11f6f850f78b4e61aac88b8c2b
|
4
|
+
data.tar.gz: a5fc6b15f83541d095d8a41f43a948f16425ea93c0e1d699ad31bbd0d3193667
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e17156f25a2517c1fe3a4cb28476697a0ed327bdce8411ce995c7b5f2695b32596041f649a1071991e2fa88531cb0b2429e69ce0707039c5a515d787813f89b4
|
7
|
+
data.tar.gz: 0e08c630c58bb7bee22172548b6137040c073bf8f3d2e1f619b4aa11fbe86a65bd5a7593a1b05ec9ed80f64f243e4cc6ba48610103cee48f640734f4f5778831
|
data/Gemfile.lock
CHANGED
@@ -1,48 +1,48 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
historical_dating (1.
|
4
|
+
historical_dating (1.8.0)
|
5
5
|
activesupport (>= 3.0.0)
|
6
|
-
parslet (~>
|
6
|
+
parslet (~> 2.0.0)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
activesupport (6.0.3.
|
11
|
+
activesupport (6.0.3.4)
|
12
12
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
13
|
i18n (>= 0.7, < 2)
|
14
14
|
minitest (~> 5.1)
|
15
15
|
tzinfo (~> 1.1)
|
16
16
|
zeitwerk (~> 2.2, >= 2.2.2)
|
17
|
-
coderay (1.1.
|
18
|
-
concurrent-ruby (1.1.
|
19
|
-
diff-lcs (1.
|
20
|
-
i18n (1.8.
|
17
|
+
coderay (1.1.3)
|
18
|
+
concurrent-ruby (1.1.8)
|
19
|
+
diff-lcs (1.4.4)
|
20
|
+
i18n (1.8.9)
|
21
21
|
concurrent-ruby (~> 1.0)
|
22
|
-
method_source (0.
|
23
|
-
minitest (5.
|
24
|
-
parslet (
|
25
|
-
pry (0.
|
26
|
-
coderay (~> 1.1
|
27
|
-
method_source (~>
|
22
|
+
method_source (1.0.0)
|
23
|
+
minitest (5.14.1)
|
24
|
+
parslet (2.0.0)
|
25
|
+
pry (0.13.1)
|
26
|
+
coderay (~> 1.1)
|
27
|
+
method_source (~> 1.0)
|
28
28
|
rake (12.3.3)
|
29
29
|
rspec (3.9.0)
|
30
30
|
rspec-core (~> 3.9.0)
|
31
31
|
rspec-expectations (~> 3.9.0)
|
32
32
|
rspec-mocks (~> 3.9.0)
|
33
|
-
rspec-core (3.9.
|
34
|
-
rspec-support (~> 3.9.
|
35
|
-
rspec-expectations (3.9.
|
33
|
+
rspec-core (3.9.2)
|
34
|
+
rspec-support (~> 3.9.3)
|
35
|
+
rspec-expectations (3.9.2)
|
36
36
|
diff-lcs (>= 1.2.0, < 2.0)
|
37
37
|
rspec-support (~> 3.9.0)
|
38
38
|
rspec-mocks (3.9.1)
|
39
39
|
diff-lcs (>= 1.2.0, < 2.0)
|
40
40
|
rspec-support (~> 3.9.0)
|
41
|
-
rspec-support (3.9.
|
41
|
+
rspec-support (3.9.3)
|
42
42
|
thread_safe (0.3.6)
|
43
|
-
tzinfo (1.2.
|
43
|
+
tzinfo (1.2.9)
|
44
44
|
thread_safe (~> 0.1)
|
45
|
-
zeitwerk (2.
|
45
|
+
zeitwerk (2.4.1)
|
46
46
|
|
47
47
|
PLATFORMS
|
48
48
|
ruby
|
@@ -55,4 +55,4 @@ DEPENDENCIES
|
|
55
55
|
rspec (~> 3.9.0)
|
56
56
|
|
57
57
|
BUNDLED WITH
|
58
|
-
2.
|
58
|
+
2.2.8
|
data/README.md
CHANGED
@@ -22,7 +22,7 @@ Or install it yourself as:
|
|
22
22
|
## Usage
|
23
23
|
|
24
24
|
~~~ruby
|
25
|
-
hd =
|
25
|
+
hd = HistoricalDating.parse("2. Jahrhundert nach Christus")
|
26
26
|
hd.from
|
27
27
|
# => #<Date: 0100-01-01 ((1757583j,0s,0n),+0s,2299161j)>
|
28
28
|
hd.to
|
@@ -33,11 +33,10 @@ hd.julian_range
|
|
33
33
|
|
34
34
|
## Development
|
35
35
|
|
36
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
36
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rspec` to run the tests. In order to run a single test, execute: `bundle exec rspec <test-filename>:<test-line-number>`. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
37
37
|
|
38
38
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
39
39
|
|
40
40
|
## Contributing
|
41
41
|
|
42
42
|
Bug reports and pull requests are welcome on GitHub at https://github.com/wendig-ou/historical_dating.
|
43
|
-
|
data/historical_dating.gemspec
CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
27
|
spec.require_paths = ["lib"]
|
28
28
|
|
29
|
-
spec.add_runtime_dependency 'parslet', '~>
|
29
|
+
spec.add_runtime_dependency 'parslet', '~> 2.0.0'
|
30
30
|
spec.add_runtime_dependency 'activesupport', '>= 3.0.0'
|
31
31
|
|
32
32
|
spec.add_development_dependency 'rspec', '~> 3.9.0'
|
data/lib/historical_dating.rb
CHANGED
@@ -18,6 +18,7 @@ module HistoricalDating
|
|
18
18
|
|
19
19
|
autoload :Api, 'historical_dating/api'
|
20
20
|
autoload :Parser, 'historical_dating/parser'
|
21
|
+
autoload :PreTransform, 'historical_dating/pre_transform'
|
21
22
|
autoload :Range, 'historical_dating/range'
|
22
23
|
autoload :Transform, 'historical_dating/transform'
|
23
24
|
|
@@ -3,53 +3,147 @@ class HistoricalDating::Parser < Parslet::Parser
|
|
3
3
|
|
4
4
|
rule(:zero){ str '0' }
|
5
5
|
rule(:natural_number){ match['1-9'] >> match['0-9'].repeat }
|
6
|
+
rule(:two_digit_natural_number){ match['1-9'] >> match['0-9'].repeat(0,1) }
|
7
|
+
rule(:more_than_two_digit_natural_number){ match['1-9'] >> match['0-9'].repeat(2,nil) }
|
6
8
|
rule(:positive_number){ zero | natural_number }
|
9
|
+
rule(:two_digit_positive_number){ zero | two_digit_natural_number }
|
10
|
+
rule(:more_than_two_digit_positive_number){ zero | more_than_two_digit_natural_number }
|
7
11
|
rule(:minus){ match '-' }
|
12
|
+
rule(:whole_number_without_zero){ natural_number | minus >> natural_number }
|
13
|
+
rule(:whole_number_with_zero){ positive_number | minus >> natural_number }
|
14
|
+
rule(:two_digit_whole_number_with_zero){ two_digit_positive_number | minus >> two_digit_natural_number }
|
15
|
+
rule(:more_than_two_digit_whole_number_with_zero){ more_than_two_digit_positive_number | minus >> more_than_two_digit_natural_number }
|
8
16
|
rule(:whole_number){ positive_number | minus >> natural_number }
|
9
|
-
rule(:day){ match['1-2'] >> match['0-9'] | str('3') >> match['0-1'] | match['1-9'] | str('0') >> match['1-9'] }
|
10
|
-
rule(:month){ str('1') >> match['0-2'] | match['1-9'] | str('0') >> match['1-9'] }
|
11
17
|
|
12
18
|
# Utility
|
13
19
|
|
14
20
|
rule(:space){ str(' ').repeat(1, nil) }
|
21
|
+
rule(:prefix){ (str('von') | str('zwischen') | str('Zwischen')) >> space }
|
15
22
|
rule(:christ){ str('Chr.') | str('Christus') }
|
16
|
-
rule(:
|
17
|
-
rule(:
|
18
|
-
rule(:
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
23
|
+
rule(:age_before){ str('v.') | str('vor') }
|
24
|
+
rule(:age_after){ str('n.') | str('nach') }
|
25
|
+
rule(:ac){
|
26
|
+
age_after >> space >> christ |
|
27
|
+
str('AC') |
|
28
|
+
str('Ac') |
|
29
|
+
str('Anno Domini') |
|
30
|
+
str('A. D.') |
|
31
|
+
str('AD')
|
32
|
+
}
|
33
|
+
rule(:bc){
|
34
|
+
age_before >> space >> christ |
|
35
|
+
str('BC') |
|
36
|
+
str('Bc')
|
37
|
+
}
|
38
|
+
rule(:acbc){
|
39
|
+
ac | bc
|
40
|
+
}
|
41
|
+
rule(:century_string){
|
42
|
+
str('Jahrhundert') |
|
43
|
+
str('Jhd.') |
|
44
|
+
str('jhd.') |
|
45
|
+
str('Jhd') |
|
46
|
+
str('jhd') |
|
47
|
+
str('Jh.') |
|
48
|
+
str('jh.') |
|
49
|
+
str('Jh') |
|
50
|
+
str('jh')
|
51
|
+
}
|
52
|
+
rule(:approx){ str('ca.') | str('Ca.') | str('ca') | str('um') | str('Um') | str('circa') }
|
53
|
+
rule(:unknown){ str('?') | str('unbekannt') | str('onbekend') }
|
54
|
+
rule(:to_characters){
|
55
|
+
str('bis') | str('-') | str('–') | str('/') | str('und')
|
56
|
+
}
|
57
|
+
rule(:to_two_digit_year){
|
58
|
+
(space >> to_characters >> space) |
|
59
|
+
(to_characters >> space) |
|
60
|
+
(space >> to_characters) |
|
61
|
+
str('/') | str('-')
|
62
|
+
}
|
63
|
+
rule(:to){
|
64
|
+
to_two_digit_year | str('-') | str('–')
|
65
|
+
}
|
66
|
+
rule(:before){ (str('vor') | str('Vor') | str('before')) >> space }
|
67
|
+
rule(:after){ (str('Nach') | str('nach') | str('ab') | str('after')) >> space }
|
24
68
|
rule(:negate){ str('nicht') >> space }
|
25
|
-
rule(:part){
|
69
|
+
rule(:part){
|
70
|
+
str('Anfang') |
|
71
|
+
str('Mitte') |
|
72
|
+
str('Ende') |
|
73
|
+
str('1. Hälfte') |
|
74
|
+
str('2. Hälfte') |
|
75
|
+
str('1. Drittel') |
|
76
|
+
str('2. Drittel') |
|
77
|
+
str('3. Drittel') |
|
78
|
+
str('1. Viertel') |
|
79
|
+
str('2. Viertel') |
|
80
|
+
str('3. Viertel') |
|
81
|
+
str('4. Viertel')
|
82
|
+
}
|
26
83
|
|
27
84
|
# Dating
|
28
85
|
|
29
|
-
rule(:
|
30
|
-
rule(:
|
31
|
-
rule(:
|
32
|
-
rule(:
|
33
|
-
rule(:
|
86
|
+
rule(:day){ match['1-2'] >> match['0-9'] | str('3') >> match['0-1'] | match['1-9'] | str('0') >> match['1-9'] }
|
87
|
+
rule(:month){ (str('0') >> match['1-9']) | (str('1') >> match['0-2']) | match['1-9'] }
|
88
|
+
rule(:two_digit_year){ (approx >> space).maybe.as(:approx) >> two_digit_whole_number_with_zero.as(:num) >> (space >> acbc).maybe.as(:acbc) }
|
89
|
+
rule(:more_than_two_digit_year){ (approx >> space).maybe.as(:approx) >> more_than_two_digit_whole_number_with_zero.as(:num) >> (space >> acbc).maybe.as(:acbc) }
|
90
|
+
rule(:year){ (approx >> space).maybe.as(:approx) >> whole_number_with_zero.as(:num) >> (space >> acbc).maybe.as(:acbc) }
|
91
|
+
rule(:century){
|
92
|
+
(approx >> space).maybe.as(:approx) >>
|
93
|
+
natural_number.as(:num) >>
|
94
|
+
((str('.').as(:cd) >> space.maybe >> century_string.as(:cs).maybe >> space.maybe >> acbc.maybe.as(:acbc)) |
|
95
|
+
(space >> century_string.as(:cs) >> (space >> acbc).maybe.as(:acbc)))
|
96
|
+
}
|
97
|
+
rule(:century_number){
|
98
|
+
(approx >> space).maybe.as(:approx) >>
|
99
|
+
natural_number.as(:num) >>
|
100
|
+
(space >> century_string).maybe.as(:cs) >>
|
101
|
+
(space >> acbc).maybe.as(:acbc)
|
102
|
+
}
|
103
|
+
rule(:century_part){ part.as(:part) >> space >> positive_number.as(:num) >> str('.') >> space >> century_string.as(:cs) >> (space >> acbc).maybe.as(:acbc) }
|
104
|
+
rule(:european_date){
|
105
|
+
(day.as(:day) >> (str('.') | str('-') | str('/')) >>
|
106
|
+
month.as(:month) >>
|
107
|
+
(str('.') | str('-') | str('/')) >>
|
108
|
+
whole_number.as(:yearnum)) |
|
109
|
+
(month.as(:month) >>
|
110
|
+
(str('.') | str('-') | str('/')) >>
|
111
|
+
whole_number.as(:yearnum))
|
112
|
+
}
|
113
|
+
rule(:machine_date){ whole_number.as(:yearnum) >> (str('.') | str('-') | str('–')) >> month.as(:month) >> (str('.') | str('-')) >> day.as(:day) }
|
34
114
|
rule(:date){ european_date | machine_date }
|
35
115
|
rule(:date_interval){ date.as(:from) >> to >> date.as(:to) }
|
36
|
-
rule(:century_interval){
|
116
|
+
rule(:century_interval){
|
117
|
+
prefix.maybe >>
|
118
|
+
(century.as(:from) | century_number.as(:from)) >>
|
119
|
+
to >>
|
120
|
+
century.as(:to)
|
121
|
+
}
|
37
122
|
rule(:before_year){ negate.maybe.as(:not) >> before >> year.as(:date) }
|
38
123
|
rule(:after_year){ negate.maybe.as(:not) >> after >> year.as(:date) }
|
39
|
-
rule(:year_interval){
|
124
|
+
rule(:year_interval){
|
125
|
+
prefix.maybe >>
|
126
|
+
(year | unknown).as(:from) >>
|
127
|
+
((to >> (more_than_two_digit_year | unknown).as(:to)) |
|
128
|
+
(to_two_digit_year >> two_digit_year.as(:to)))
|
129
|
+
}
|
130
|
+
rule(:before_century){ before >> century.as(:century) }
|
131
|
+
|
40
132
|
rule(:interval){
|
41
133
|
before_year.as(:before_year) |
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
134
|
+
after_year.as(:after_year) |
|
135
|
+
date_interval.as(:date_interval) |
|
136
|
+
century_interval.as(:century_interval) |
|
137
|
+
year_interval.as(:year_interval) |
|
138
|
+
before_century.as(:before_century)
|
46
139
|
}
|
140
|
+
|
47
141
|
rule(:dating){
|
48
142
|
interval.as(:interval) |
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
143
|
+
century_part.as(:century_part) |
|
144
|
+
century.as(:century) |
|
145
|
+
date.as(:date) |
|
146
|
+
year.as(:year)
|
53
147
|
}
|
54
148
|
|
55
149
|
root(:dating)
|
@@ -57,6 +151,8 @@ class HistoricalDating::Parser < Parslet::Parser
|
|
57
151
|
# Transform
|
58
152
|
|
59
153
|
def transform(input)
|
60
|
-
|
154
|
+
result = self.class.new.parse(input)
|
155
|
+
result = HistoricalDating::PreTransform.new.apply(result)
|
156
|
+
HistoricalDating::Transform.new.apply(result)
|
61
157
|
end
|
62
158
|
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
class HistoricalDating::PreTransform < Parslet::Transform
|
2
|
+
rule(from: subtree(:from), to: subtree(:to)) do
|
3
|
+
bc = to[:acbc] && (to[:acbc].match(/(vor|v.) (Chr.|Christus)/) || to[:acbc].match(/B(C|c)/))
|
4
|
+
|
5
|
+
if bc
|
6
|
+
from[:acbc] = to[:acbc]
|
7
|
+
end
|
8
|
+
|
9
|
+
# To detect the first range of e.g.: 2. - 3. Jhd, :acbc key is needed.
|
10
|
+
# TODO: Find a better solution.
|
11
|
+
if from.is_a?(Hash) && to.is_a?(Hash) && !from.key?(:acbc) && to.key?(:acbc) && !to[:acbc]
|
12
|
+
from[:acbc] = nil
|
13
|
+
end
|
14
|
+
|
15
|
+
if !bc && to[:num].to_s.size == 2 && to[:cs].nil?
|
16
|
+
# for e.g.: 1890/91 but not for e.g.: 150 - 60 v. Chr.
|
17
|
+
to[:num] = (from[:num].to_i / 100).to_s + to[:num]
|
18
|
+
end
|
19
|
+
|
20
|
+
{from: from, to: to}
|
21
|
+
end
|
22
|
+
|
23
|
+
# detect century by :cd and add :cs
|
24
|
+
rule(num: simple(:num), approx: simple(:approx), acbc: simple(:acbc), cd: simple(:cd)) do |data|
|
25
|
+
if data[:cd]
|
26
|
+
data.delete :cd
|
27
|
+
data.merge(
|
28
|
+
cs: 'Jahrhundert'
|
29
|
+
)
|
30
|
+
else
|
31
|
+
data.delete :cd
|
32
|
+
data
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# detect century by :cd and add :cs
|
37
|
+
rule(num: simple(:num), approx: simple(:approx), cd: simple(:cd)) do |data|
|
38
|
+
if data[:cd]
|
39
|
+
data.delete :cd
|
40
|
+
data.merge(
|
41
|
+
cs: 'Jahrhundert'
|
42
|
+
)
|
43
|
+
else
|
44
|
+
data.delete :cd
|
45
|
+
data
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# remove :cd if :cs already present (with acbc)
|
50
|
+
rule(num: simple(:num), approx: simple(:approx), acbc: simple(:acbc), cd: simple(:cd), cs: simple(:cs)) do |data|
|
51
|
+
data.delete :cd
|
52
|
+
data
|
53
|
+
end
|
54
|
+
|
55
|
+
# remove :cd if :cs already present (no acbc)
|
56
|
+
rule(num: simple(:num), approx: simple(:approx), cd: simple(:cd), cs: simple(:cs)) do |data|
|
57
|
+
data.delete :cd
|
58
|
+
data
|
59
|
+
end
|
60
|
+
|
61
|
+
# remove :prefix
|
62
|
+
rule(prefix: simple(:prefix)) do |data|
|
63
|
+
data.delete :prefix
|
64
|
+
data
|
65
|
+
end
|
66
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
class HistoricalDating::Transform < Parslet::Transform
|
2
|
-
rule(:num => simple(:num), :part => simple(:part), :
|
2
|
+
rule(:num => simple(:num), :part => simple(:part), :acbc => simple(:acbc), :cs => simple(:cs)) do
|
3
3
|
modifier = case part
|
4
4
|
when "Anfang" then [0, 75]
|
5
5
|
when "Mitte" then [35, 35]
|
@@ -15,7 +15,7 @@ class HistoricalDating::Transform < Parslet::Transform
|
|
15
15
|
when "4. Viertel" then [75, 0]
|
16
16
|
end
|
17
17
|
|
18
|
-
if
|
18
|
+
if HistoricalDating::Transform.ac?(acbc)
|
19
19
|
{
|
20
20
|
:from => Date.new((num.to_i - 1) * 100 + modifier.first, 1, 1),
|
21
21
|
:to => Date.new((num.to_i - 1) * 100 + 99 - modifier.last, 12, 31)
|
@@ -28,8 +28,8 @@ class HistoricalDating::Transform < Parslet::Transform
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
rule(:num => simple(:num), :approx => simple(:approx), :
|
32
|
-
result = if
|
31
|
+
rule(:num => simple(:num), :approx => simple(:approx), :acbc => simple(:acbc), :cs => simple(:cs)) do
|
32
|
+
result = if HistoricalDating::Transform.ac?(acbc)
|
33
33
|
{
|
34
34
|
:from => Date.new((num.to_i - 1) * 100, 1, 1),
|
35
35
|
:to => Date.new((num.to_i - 1) * 100 + 99, 12, 31)
|
@@ -49,10 +49,10 @@ class HistoricalDating::Transform < Parslet::Transform
|
|
49
49
|
result
|
50
50
|
end
|
51
51
|
|
52
|
-
rule(:num => simple(:num), :approx => simple(:approx), :
|
52
|
+
rule(:num => simple(:num), :approx => simple(:approx), :acbc => simple(:acbc)) do
|
53
53
|
modifier = (approx ? 5 : 0)
|
54
54
|
|
55
|
-
if
|
55
|
+
if HistoricalDating::Transform.ac?(acbc)
|
56
56
|
{
|
57
57
|
:from => Date.new(num.to_i - modifier, 1, 1),
|
58
58
|
:to => Date.new(num.to_i + modifier, 12, 31)
|
@@ -76,6 +76,13 @@ class HistoricalDating::Transform < Parslet::Transform
|
|
76
76
|
}
|
77
77
|
end
|
78
78
|
|
79
|
+
rule(:month => simple(:month), :yearnum => simple(:yearnum)) do
|
80
|
+
{
|
81
|
+
:from => Date.new(yearnum.to_i, month.to_i, 1),
|
82
|
+
:to => Date.new(yearnum.to_i, month.to_i, -1),
|
83
|
+
}
|
84
|
+
end
|
85
|
+
|
79
86
|
rule(:date => {:from => simple(:from), :to => simple(:to)}) do
|
80
87
|
{:from => from, :to => to}
|
81
88
|
end
|
@@ -84,8 +91,16 @@ class HistoricalDating::Transform < Parslet::Transform
|
|
84
91
|
{:from => first_from, :to => last_to}
|
85
92
|
end
|
86
93
|
|
94
|
+
rule(before_century: {from: simple(:from), to: simple(:to) }) do
|
95
|
+
{from: from - 100.years, to: to - 100.years}
|
96
|
+
end
|
97
|
+
|
87
98
|
[:century, :date_interval, :year, :year_interval, :interval, :century_interval, :century_part].each do |key|
|
88
99
|
rule(key => {:from => simple(:from), :to => simple(:to)}) do
|
100
|
+
if to < from
|
101
|
+
raise HistoricalDating::Error, 'from_later_than_to'
|
102
|
+
end
|
103
|
+
|
89
104
|
{:from => from, :to => to}
|
90
105
|
end
|
91
106
|
end
|
@@ -128,6 +143,10 @@ class HistoricalDating::Transform < Parslet::Transform
|
|
128
143
|
end
|
129
144
|
end
|
130
145
|
|
146
|
+
def self.ac?(acbc)
|
147
|
+
acbc.nil? || acbc.match(/(nach|n.) (Chr.|Christus)/) || acbc.match(/AC|Ac|Anno Domini|A. D.|AD/)
|
148
|
+
end
|
149
|
+
|
131
150
|
def self.open_start(year)
|
132
151
|
return {
|
133
152
|
from: Date.new(year - distance(year), 1, 1),
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: historical_dating
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Moritz Schepp
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parslet
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 2.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activesupport
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -89,6 +89,7 @@ files:
|
|
89
89
|
- lib/historical_dating.rb
|
90
90
|
- lib/historical_dating/api.rb
|
91
91
|
- lib/historical_dating/parser.rb
|
92
|
+
- lib/historical_dating/pre_transform.rb
|
92
93
|
- lib/historical_dating/range.rb
|
93
94
|
- lib/historical_dating/transform.rb
|
94
95
|
- lib/historical_dating/version.rb
|