historical_dating 1.0.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 52e37df032c7bec594220049a78d9948f84c19636c6cd7024cc254b4ecdf3d93
4
- data.tar.gz: 1669cf029983cf0753305f9b719f7533d6c541cfe1b0a80183ac13d4558342b6
3
+ metadata.gz: 5626f5c1b07674a6546b19aa32011ecbd3b78699c9c2b86533708fc83f20d80d
4
+ data.tar.gz: 946a0c51e02776a04847d35a7671226af38134fa2c55c14031a4b942912e77d0
5
5
  SHA512:
6
- metadata.gz: 9dcaf8f69b1b8261228945eb6fa2797853b8f36591ed2bb43be6f31c345b2d7f89524e3db2ea7743f0937deb289ef119314f15d55f852cead9d8039df963de00
7
- data.tar.gz: 9710644a1f488711f1d4520df46551201410ee104b7d17c63251cdbcf34fbf3b17304f0cf453703cbb604dcea5ca76f8df31cf188dbda039faf789ee969eb164
6
+ metadata.gz: c1446b31cb59adf40e9ebac90a3479131dc8dccbac9e8b38442399cba282e6773b290f7a41c5f15b2b349278fb8deff4256cb341ce59f5c4b4d01637a940445f
7
+ data.tar.gz: e3f755f48886b00c478934e2f66307c71f3b8fb1011d98d4f7e47f562f51e11d9ff9977f97eff84547278f10cb50c14b7c317b7ab0d60509456243bad055ffda
@@ -1,48 +1,48 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- historical_dating (1.0.0)
4
+ historical_dating (1.7.0)
5
5
  activesupport (>= 3.0.0)
6
- parslet (~> 1.8)
6
+ parslet (~> 2.0.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activesupport (6.0.2.1)
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
- zeitwerk (~> 2.2)
17
- coderay (1.1.2)
18
- concurrent-ruby (1.1.6)
19
- diff-lcs (1.3)
20
- i18n (1.8.2)
16
+ zeitwerk (~> 2.2, >= 2.2.2)
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.9.2)
23
- minitest (5.13.0)
24
- parslet (1.8.2)
25
- pry (0.12.2)
26
- coderay (~> 1.1.0)
27
- method_source (~> 0.9.0)
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.1)
34
- rspec-support (~> 3.9.1)
35
- rspec-expectations (3.9.0)
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.2)
41
+ rspec-support (3.9.3)
42
42
  thread_safe (0.3.6)
43
- tzinfo (1.2.6)
43
+ tzinfo (1.2.8)
44
44
  thread_safe (~> 0.1)
45
- zeitwerk (2.2.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 = HistoryDating.parse("2. Jahrhundert nach Christus")
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
-
@@ -8,14 +8,14 @@ Gem::Specification.new do |spec|
8
8
 
9
9
  spec.summary = "Parse human historical datings"
10
10
  spec.description = "Parse human historical datings and convert them to Julian day ranges"
11
- spec.homepage = "https://github.com/wendig-ou/historical-dating"
11
+ spec.homepage = "https://github.com/wendig-ou/historical_dating"
12
12
  spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
13
 
14
14
  spec.metadata["allowed_push_host"] = "https://rubygems.org"
15
15
 
16
16
  spec.metadata["homepage_uri"] = spec.homepage
17
- spec.metadata["source_code_uri"] = "https://github.com/wendig-ou/historical-dating"
18
- spec.metadata["changelog_uri"] = "https://github.com/wendig-ou/historical-dating/blob/master/CHANGELOG.md"
17
+ spec.metadata["source_code_uri"] = "https://github.com/wendig-ou/historical_dating"
18
+ spec.metadata["changelog_uri"] = "https://github.com/wendig-ou/historical_dating/blob/master/CHANGELOG.md"
19
19
 
20
20
  # Specify which files should be added to the gem when it is released.
21
21
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -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', '~> 1.8'
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'
@@ -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
 
@@ -15,4 +15,4 @@ module HistoricalDating::Api
15
15
  result = parser.transform(string)
16
16
  HistoricalDating::Range.new(result[:from], result[:to])
17
17
  end
18
- end
18
+ end
@@ -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(:age){ str('v.') | str('vor') }
17
- rule(:bc){ age >> space >> christ }
18
- rule(:century_string){ str('Jahrhundert') | str('Jh.') }
19
- rule(:approx){ str('ca.') | str('um') | str('circa') }
20
- rule(:unknown){ str('?') }
21
- rule(:to){ space >> str('bis') >> space }
22
- rule(:before){ str('vor') >> space }
23
- rule(:after){ str('nach') >> space }
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('und')
56
+ }
57
+ rule(:to_two_digit_year){
58
+ (space >> to_characters >> space) |
59
+ (to_characters >> space) |
60
+ (space >> to_characters) |
61
+ str('/')
62
+ }
63
+ rule(:to){
64
+ to_two_digit_year | 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){ str('Anfang') | str('Mitte') | str('Ende') | str('1. Hälfte') | str('2. Hälfte') | str('1. Drittel') | str('2. Drittel') | str('3. Drittel') }
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(:century){ (approx >> space).maybe.as(:approx) >> positive_number.as(:num) >> str('.') >> space >> century_string.as(:cs) >> (space >> bc).maybe.as(:bc) }
30
- rule(:year){ (approx >> space).maybe.as(:approx) >> natural_number.as(:num) >> (space >> bc).maybe.as(:bc) }
31
- rule(:century_part){ part.as(:part) >> space >> positive_number.as(:num) >> str('.') >> space >> century_string.as(:cs) >> (space >> bc).maybe.as(:bc) }
32
- rule(:european_date){ day.as(:day) >> str('.') >> month.as(:month) >> str('.') >> whole_number.as(:yearnum) }
33
- rule(:machine_date){ whole_number.as(:yearnum) >> (str('.') | str('-')) >> month.as(:month) >> (str('.') | str('-')) >> day.as(:day) }
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 >> century_string.as(:cs) >> (space >> acbc).maybe.as(:acbc)).maybe) |
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('-')) >> month.as(:month) >> ((str('.') | str('-')) >> day.as(:day)).maybe }
34
114
  rule(:date){ european_date | machine_date }
35
115
  rule(:date_interval){ date.as(:from) >> to >> date.as(:to) }
36
- rule(:century_interval){ century.as(:from) >> to >> century.as(:to) }
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){ year.as(:from) >> to >> (year | unknown).as(:to) | (year | unknown).as(:from) >> to >> year.as(:to) }
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
- after_year.as(:after_year) |
43
- date_interval.as(:date_interval) |
44
- century_interval.as(:century_interval) |
45
- year_interval.as(:year_interval)
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
- century_part.as(:century_part) |
50
- century.as(:century) |
51
- date.as(:date) |
52
- year.as(:year)
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
- HistoricalDating::Transform.new.apply(self.class.new.parse(input))
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
@@ -9,4 +9,12 @@ class HistoricalDating::Range
9
9
  def julian_range
10
10
  [from.jd, to.jd]
11
11
  end
12
- end
12
+
13
+ def from_time
14
+ Time.mktime(from.year, from.month, from.day)
15
+ end
16
+
17
+ def to_time
18
+ Time.mktime(to.year, to.month, to.day, 23, 59, 59)
19
+ end
20
+ end
@@ -1,17 +1,21 @@
1
1
  class HistoricalDating::Transform < Parslet::Transform
2
- rule(:num => simple(:num), :part => simple(:part), :bc => simple(:bc), :cs => simple(:cs)) do
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]
6
6
  when "Ende" then [75, 0]
7
7
  when "1. Hälfte" then [0, 50]
8
8
  when "2. Hälfte" then [50, 0]
9
- when "1. Drittel" then [0, 66]
10
- when "2. Drittel" then [33, 33]
9
+ when "1. Drittel" then [0, 67]
10
+ when "2. Drittel" then [33, 34]
11
11
  when "3. Drittel" then [66, 0]
12
+ when "1. Viertel" then [0, 75]
13
+ when "2. Viertel" then [25, 50]
14
+ when "3. Viertel" then [50, 25]
15
+ when "4. Viertel" then [75, 0]
12
16
  end
13
17
 
14
- if bc.nil?
18
+ if HistoricalDating::Transform.ac?(acbc)
15
19
  {
16
20
  :from => Date.new((num.to_i - 1) * 100 + modifier.first, 1, 1),
17
21
  :to => Date.new((num.to_i - 1) * 100 + 99 - modifier.last, 12, 31)
@@ -24,8 +28,8 @@ class HistoricalDating::Transform < Parslet::Transform
24
28
  end
25
29
  end
26
30
 
27
- rule(:num => simple(:num), :approx => simple(:approx), :bc => simple(:bc), :cs => simple(:cs)) do
28
- result = if bc.nil?
31
+ rule(:num => simple(:num), :approx => simple(:approx), :acbc => simple(:acbc), :cs => simple(:cs)) do
32
+ result = if HistoricalDating::Transform.ac?(acbc)
29
33
  {
30
34
  :from => Date.new((num.to_i - 1) * 100, 1, 1),
31
35
  :to => Date.new((num.to_i - 1) * 100 + 99, 12, 31)
@@ -45,10 +49,10 @@ class HistoricalDating::Transform < Parslet::Transform
45
49
  result
46
50
  end
47
51
 
48
- rule(:num => simple(:num), :approx => simple(:approx), :bc => simple(:bc)) do
52
+ rule(:num => simple(:num), :approx => simple(:approx), :acbc => simple(:acbc)) do
49
53
  modifier = (approx ? 5 : 0)
50
54
 
51
- if bc.nil?
55
+ if HistoricalDating::Transform.ac?(acbc)
52
56
  {
53
57
  :from => Date.new(num.to_i - modifier, 1, 1),
54
58
  :to => Date.new(num.to_i + modifier, 12, 31)
@@ -72,6 +76,13 @@ class HistoricalDating::Transform < Parslet::Transform
72
76
  }
73
77
  end
74
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
+
75
86
  rule(:date => {:from => simple(:from), :to => simple(:to)}) do
76
87
  {:from => from, :to => to}
77
88
  end
@@ -80,8 +91,16 @@ class HistoricalDating::Transform < Parslet::Transform
80
91
  {:from => first_from, :to => last_to}
81
92
  end
82
93
 
94
+ rule(before_century: {from: simple(:from), to: simple(:to) }) do
95
+ {from: from - 100.years, to: to - 100.years}
96
+ end
97
+
83
98
  [:century, :date_interval, :year, :year_interval, :interval, :century_interval, :century_part].each do |key|
84
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
+
85
104
  {:from => from, :to => to}
86
105
  end
87
106
  end
@@ -124,6 +143,10 @@ class HistoricalDating::Transform < Parslet::Transform
124
143
  end
125
144
  end
126
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
+
127
150
  def self.open_start(year)
128
151
  return {
129
152
  from: Date.new(year - distance(year), 1, 1),
@@ -1,3 +1,3 @@
1
1
  module HistoricalDating
2
- VERSION = "1.0.0"
2
+ VERSION = "1.7.0"
3
3
  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.0.0
4
+ version: 1.7.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-02-18 00:00:00.000000000 Z
11
+ date: 2021-01-13 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: '1.8'
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: '1.8'
26
+ version: 2.0.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -89,16 +89,17 @@ 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
95
- homepage: https://github.com/wendig-ou/historical-dating
96
+ homepage: https://github.com/wendig-ou/historical_dating
96
97
  licenses: []
97
98
  metadata:
98
99
  allowed_push_host: https://rubygems.org
99
- homepage_uri: https://github.com/wendig-ou/historical-dating
100
- source_code_uri: https://github.com/wendig-ou/historical-dating
101
- changelog_uri: https://github.com/wendig-ou/historical-dating/blob/master/CHANGELOG.md
100
+ homepage_uri: https://github.com/wendig-ou/historical_dating
101
+ source_code_uri: https://github.com/wendig-ou/historical_dating
102
+ changelog_uri: https://github.com/wendig-ou/historical_dating/blob/master/CHANGELOG.md
102
103
  post_install_message:
103
104
  rdoc_options: []
104
105
  require_paths:
@@ -114,8 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
115
  - !ruby/object:Gem::Version
115
116
  version: '0'
116
117
  requirements: []
117
- rubyforge_project:
118
- rubygems_version: 2.7.6.2
118
+ rubygems_version: 3.0.3
119
119
  signing_key:
120
120
  specification_version: 4
121
121
  summary: Parse human historical datings