historical_dating 1.1.0 → 1.4.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 +19 -19
- data/README.md +2 -3
- data/historical_dating.gemspec +1 -1
- data/lib/historical_dating.rb +1 -0
- data/lib/historical_dating/parser.rb +42 -11
- data/lib/historical_dating/pre_transform.rb +42 -0
- data/lib/historical_dating/transform.rb +14 -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: 47c1a58ce160b759e2787853d78b7aa96428fe9e2f7076fdf96158a38664902f
|
4
|
+
data.tar.gz: 236c5fadd1663f7516fa09f5504d2fc5227c0290a8739814da2ebc7e0cf1dd36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9f810f66539567fa1cdc3f83e22106d533e94c6bb334d28ca884d1dcbf60e078835cd2a8b47f2490149cc7e4063cb76ff6f7d2078afdf13a4432f447a2300fb
|
7
|
+
data.tar.gz: 6b5ce82213a10cb258cad1062eccc431aeed3444679062b3584b08771351f467c12d65209344a4677c9380365eda9dca2ef8898c9b49742a045893ac99507a0a
|
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.4.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.7)
|
19
|
+
diff-lcs (1.4.4)
|
20
|
+
i18n (1.8.5)
|
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.8)
|
44
44
|
thread_safe (~> 0.1)
|
45
|
-
zeitwerk (2.
|
45
|
+
zeitwerk (2.4.1)
|
46
46
|
|
47
47
|
PLATFORMS
|
48
48
|
ruby
|
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
|
|
@@ -5,6 +5,7 @@ class HistoricalDating::Parser < Parslet::Parser
|
|
5
5
|
rule(:natural_number){ match['1-9'] >> match['0-9'].repeat }
|
6
6
|
rule(:positive_number){ zero | natural_number }
|
7
7
|
rule(:minus){ match '-' }
|
8
|
+
rule(:whole_number_without_zero){ natural_number | minus >> natural_number }
|
8
9
|
rule(:whole_number){ positive_number | minus >> natural_number }
|
9
10
|
rule(:day){ match['1-2'] >> match['0-9'] | str('3') >> match['0-1'] | match['1-9'] | str('0') >> match['1-9'] }
|
10
11
|
rule(:month){ str('1') >> match['0-2'] | match['1-9'] | str('0') >> match['1-9'] }
|
@@ -13,22 +14,43 @@ class HistoricalDating::Parser < Parslet::Parser
|
|
13
14
|
|
14
15
|
rule(:space){ str(' ').repeat(1, nil) }
|
15
16
|
rule(:christ){ str('Chr.') | str('Christus') }
|
16
|
-
rule(:age){ str('v.') | str('vor') }
|
17
|
-
rule(:
|
18
|
-
rule(:century_string){ str('Jahrhundert') | str('Jh.') }
|
17
|
+
rule(:age){ str('v.') | str('vor') | str('n.') | str('nach') }
|
18
|
+
rule(:acbc){ age >> space >> christ | str('BC') | str('AC') }
|
19
|
+
rule(:century_string){ str('Jahrhundert') | str('Jh.') | str('Jhd') }
|
19
20
|
rule(:approx){ str('ca.') | str('um') | str('circa') }
|
20
21
|
rule(:unknown){ str('?') }
|
21
|
-
rule(:to){
|
22
|
+
rule(:to){
|
23
|
+
((space >> (str('bis') | str('-') | str('/')) >> space) |
|
24
|
+
str('-') |
|
25
|
+
str('/'))
|
26
|
+
}
|
22
27
|
rule(:before){ str('vor') >> space }
|
23
28
|
rule(:after){ str('nach') >> space }
|
24
29
|
rule(:negate){ str('nicht') >> space }
|
25
|
-
rule(:part){
|
30
|
+
rule(:part){
|
31
|
+
str('Anfang') |
|
32
|
+
str('Mitte') |
|
33
|
+
str('Ende') |
|
34
|
+
str('1. Hälfte') |
|
35
|
+
str('2. Hälfte') |
|
36
|
+
str('1. Drittel') |
|
37
|
+
str('2. Drittel') |
|
38
|
+
str('3. Drittel') |
|
39
|
+
str('1. Viertel') |
|
40
|
+
str('2. Viertel') |
|
41
|
+
str('3. Viertel') |
|
42
|
+
str('4. Viertel')
|
43
|
+
}
|
26
44
|
|
27
45
|
# Dating
|
28
46
|
|
29
|
-
rule(:century){
|
30
|
-
|
31
|
-
|
47
|
+
rule(:century){
|
48
|
+
(approx >> space).maybe.as(:approx) >>
|
49
|
+
positive_number.as(:num) >> str('.').as(:cd) >>
|
50
|
+
(space >> century_string.as(:cs) >> (space >> acbc).maybe.as(:acbc)).maybe
|
51
|
+
}
|
52
|
+
rule(:year){ (approx >> space).maybe.as(:approx) >> whole_number_without_zero.as(:num) >> (space >> acbc).maybe.as(:acbc) }
|
53
|
+
rule(:century_part){ part.as(:part) >> space >> positive_number.as(:num) >> str('.') >> space >> century_string.as(:cs) >> (space >> acbc).maybe.as(:acbc) }
|
32
54
|
rule(:european_date){ day.as(:day) >> str('.') >> month.as(:month) >> str('.') >> whole_number.as(:yearnum) }
|
33
55
|
rule(:machine_date){ whole_number.as(:yearnum) >> (str('.') | str('-')) >> month.as(:month) >> (str('.') | str('-')) >> day.as(:day) }
|
34
56
|
rule(:date){ european_date | machine_date }
|
@@ -36,14 +58,21 @@ class HistoricalDating::Parser < Parslet::Parser
|
|
36
58
|
rule(:century_interval){ century.as(:from) >> to >> century.as(:to) }
|
37
59
|
rule(:before_year){ negate.maybe.as(:not) >> before >> year.as(:date) }
|
38
60
|
rule(:after_year){ negate.maybe.as(:not) >> after >> year.as(:date) }
|
39
|
-
rule(:year_interval){
|
61
|
+
rule(:year_interval){
|
62
|
+
year.as(:from) >> to >> (year | unknown).as(:to) |
|
63
|
+
(year | unknown).as(:from) >> to >> year.as(:to)
|
64
|
+
}
|
65
|
+
rule(:before_century){ before >> century.as(:century) }
|
66
|
+
|
40
67
|
rule(:interval){
|
41
68
|
before_year.as(:before_year) |
|
42
69
|
after_year.as(:after_year) |
|
43
70
|
date_interval.as(:date_interval) |
|
44
71
|
century_interval.as(:century_interval) |
|
45
|
-
year_interval.as(:year_interval)
|
72
|
+
year_interval.as(:year_interval) |
|
73
|
+
before_century.as(:before_century)
|
46
74
|
}
|
75
|
+
|
47
76
|
rule(:dating){
|
48
77
|
interval.as(:interval) |
|
49
78
|
century_part.as(:century_part) |
|
@@ -57,6 +86,8 @@ class HistoricalDating::Parser < Parslet::Parser
|
|
57
86
|
# Transform
|
58
87
|
|
59
88
|
def transform(input)
|
60
|
-
|
89
|
+
result = self.class.new.parse(input)
|
90
|
+
result = HistoricalDating::PreTransform.new.apply(result)
|
91
|
+
HistoricalDating::Transform.new.apply(result)
|
61
92
|
end
|
62
93
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
class HistoricalDating::PreTransform < Parslet::Transform
|
2
|
+
rule(from: subtree(:from), to: subtree(:to)) do
|
3
|
+
if to[:acbc] && (to[:acbc].match(/(vor|v.) (Chr.|Christus)/) || to[:acbc].match(/BC/))
|
4
|
+
from[:acbc] = to[:acbc]
|
5
|
+
end
|
6
|
+
|
7
|
+
if to[:num].to_s.size == 2 && to[:cs].nil?
|
8
|
+
# e.g.: 1890/91
|
9
|
+
to[:num] = (from[:num].to_i / 100).to_s + to[:num]
|
10
|
+
end
|
11
|
+
|
12
|
+
{from: from, to: to}
|
13
|
+
end
|
14
|
+
|
15
|
+
# detect century by :cd and add :cs
|
16
|
+
rule(num: simple(:num), approx: simple(:approx), acbc: simple(:acbc), cd: simple(:cd)) do |data|
|
17
|
+
data.delete :cd
|
18
|
+
data.merge(
|
19
|
+
cs: 'Jahrhundert'
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
# detect century by :cd and add :cs
|
24
|
+
rule(num: simple(:num), approx: simple(:approx), cd: simple(:cd)) do |data|
|
25
|
+
data.delete :cd
|
26
|
+
data.merge(
|
27
|
+
cs: 'Jahrhundert'
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
# remove :cd if :cs already present (with acbc)
|
32
|
+
rule(num: simple(:num), approx: simple(:approx), acbc: simple(:acbc), cd: simple(:cd), cs: simple(:cs)) do |data|
|
33
|
+
data.delete :cd
|
34
|
+
data
|
35
|
+
end
|
36
|
+
|
37
|
+
# remove :cd if :cs already present (no acbc)
|
38
|
+
rule(num: simple(:num), approx: simple(:approx), cd: simple(:cd), cs: simple(:cs)) do |data|
|
39
|
+
data.delete :cd
|
40
|
+
data
|
41
|
+
end
|
42
|
+
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 acbc.nil? || acbc.match(/(nach|n.) (Chr.|Christus)/) || acbc.match(/AC/)
|
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 acbc.nil? || acbc.match(/(nach|n.) (Chr.|Christus)/) || acbc.match(/AC/)
|
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 acbc.nil? || acbc.match(/(nach|n.) (Chr.|Christus)/) || acbc.match(/AC/)
|
56
56
|
{
|
57
57
|
:from => Date.new(num.to_i - modifier, 1, 1),
|
58
58
|
:to => Date.new(num.to_i + modifier, 12, 31)
|
@@ -84,8 +84,16 @@ class HistoricalDating::Transform < Parslet::Transform
|
|
84
84
|
{:from => first_from, :to => last_to}
|
85
85
|
end
|
86
86
|
|
87
|
+
rule(before_century: {from: simple(:from), to: simple(:to) }) do
|
88
|
+
{from: from - 100.years, to: to - 100.years}
|
89
|
+
end
|
90
|
+
|
87
91
|
[:century, :date_interval, :year, :year_interval, :interval, :century_interval, :century_part].each do |key|
|
88
92
|
rule(key => {:from => simple(:from), :to => simple(:to)}) do
|
93
|
+
if to < from
|
94
|
+
raise HistoricalDating::Error, 'from_later_than_to'
|
95
|
+
end
|
96
|
+
|
89
97
|
{:from => from, :to => to}
|
90
98
|
end
|
91
99
|
end
|
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.4.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: 2020-
|
11
|
+
date: 2020-11-23 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
|