edtf-humanize 1.0.0 → 2.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.
@@ -0,0 +1,110 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'edtf-humanize'
4
+
5
+ RSpec.describe Edtf::Humanize do
6
+ before do
7
+ I18n.locale = :fr
8
+ end
9
+
10
+ it { is_expected.to be_a(Module) }
11
+
12
+ context 'with a decade' do
13
+ it 'returns a humanized decade string' do
14
+ expect(Date.edtf('199x').humanize).to eq('Les années 1990')
15
+ end
16
+ end
17
+
18
+ context 'with a century' do
19
+ it 'returns a humanized century string' do
20
+ expect(Date.edtf('19xx').humanize).to eq('XXe siècle')
21
+ end
22
+ end
23
+
24
+ context 'with an interval' do
25
+ it 'returns a humanized interval string' do
26
+ expect(Date.edtf('1970/1980').humanize).to eq('De 1970 à 1980')
27
+ end
28
+ end
29
+
30
+ context 'with an open interval' do
31
+ it 'returns a humanized interval string' do
32
+ expect(Date.edtf('1970/open').humanize).to eq('Depuis 1970')
33
+ end
34
+ end
35
+
36
+ context 'with an appoximate interval'
37
+ it 'returns a humanized approximate interval string' do
38
+ expect(Date.edtf('1970~/1980~').humanize).to(
39
+ eq('De 1970 environ à 1980 environ')
40
+ )
41
+ end
42
+
43
+ context 'with an iso date' do
44
+ it 'returns a humanized ISO date string' do
45
+ expect(Date.edtf('1975-07-01').humanize).to eq('1 Juillet 1975')
46
+ end
47
+ end
48
+
49
+ context 'with an uncertain iso date' do
50
+ it 'returns a humanized uncertain ISO date string' do
51
+ expect(Date.edtf('1975?').humanize).to eq('1975?')
52
+ end
53
+ end
54
+
55
+ context 'with an unspecfic year iso date' do
56
+ it 'returns a humanized unspecified year ISO date string' do
57
+ expect(Date.edtf('197u').humanize).to eq('197x')
58
+ end
59
+ end
60
+
61
+ context 'with a season' do
62
+ it 'returns a humanized season string' do
63
+ expect(Date.edtf('1975-22').humanize).to eq('été 1975')
64
+ end
65
+ end
66
+
67
+ context 'with a set' do
68
+ it 'returns a humanized exclusive set string' do
69
+ expect(Date.edtf('[1980, 1981, 1983]').humanize).to(
70
+ eq('1980, 1981 ou 1983')
71
+ )
72
+ end
73
+
74
+ it 'returns a humanized inclusive set string' do
75
+ expect(Date.edtf('{1980, 1981, 1983}').humanize).to(
76
+ eq('1980, 1981 et 1983')
77
+ )
78
+ end
79
+
80
+ it 'returns a humanized open (before) exclusive set string' do
81
+ expect(Date.edtf('[..1980]').humanize).to(
82
+ eq('Le ou avant 1980')
83
+ )
84
+ end
85
+
86
+ it 'returns a humanized open (after) exclusive set string' do
87
+ expect(Date.edtf('[1980..]').humanize).to(
88
+ eq('Le ou après 1980')
89
+ )
90
+ end
91
+
92
+ it 'returns a humanized open (before) inclusive set string' do
93
+ expect(Date.edtf('{..1980}').humanize).to(
94
+ eq('Le et avant 1980')
95
+ )
96
+ end
97
+
98
+ it 'returns a humanized open (after) inclusive set string' do
99
+ expect(Date.edtf('{1980..}').humanize).to(
100
+ eq('Le et après 1980')
101
+ )
102
+ end
103
+ end
104
+
105
+ context 'with an unknown value' do
106
+ it 'returns a humanized unknown string' do
107
+ expect(Date.edtf('uuuu').humanize).to eq('Inconnue')
108
+ end
109
+ end
110
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This file was generated by the `rspec --init` command. Conventionally, all
2
4
  # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
5
  # The generated `.rspec` file contains `--require spec_helper` which will cause
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: edtf-humanize
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cory Lown
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-28 00:00:00.000000000 Z
11
+ date: 2020-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: edtf
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -31,19 +45,19 @@ dependencies:
31
45
  - !ruby/object:Gem::Version
32
46
  version: '4'
33
47
  - !ruby/object:Gem::Dependency
34
- name: activesupport
48
+ name: roman
35
49
  requirement: !ruby/object:Gem::Requirement
36
50
  requirements:
37
- - - ">="
51
+ - - "~>"
38
52
  - !ruby/object:Gem::Version
39
- version: '4'
53
+ version: 0.2.0
40
54
  type: :runtime
41
55
  prerelease: false
42
56
  version_requirements: !ruby/object:Gem::Requirement
43
57
  requirements:
44
- - - ">="
58
+ - - "~>"
45
59
  - !ruby/object:Gem::Version
46
- version: '4'
60
+ version: 0.2.0
47
61
  - !ruby/object:Gem::Dependency
48
62
  name: rake
49
63
  requirement: !ruby/object:Gem::Requirement
@@ -73,19 +87,33 @@ dependencies:
73
87
  - !ruby/object:Gem::Version
74
88
  version: '3.9'
75
89
  - !ruby/object:Gem::Dependency
76
- name: bump
90
+ name: rubocop
77
91
  requirement: !ruby/object:Gem::Requirement
78
92
  requirements:
79
- - - ">="
93
+ - - "~>"
80
94
  - !ruby/object:Gem::Version
81
- version: '0'
95
+ version: '0.87'
82
96
  type: :development
83
97
  prerelease: false
84
98
  version_requirements: !ruby/object:Gem::Requirement
85
99
  requirements:
86
- - - ">="
100
+ - - "~>"
87
101
  - !ruby/object:Gem::Version
88
- version: '0'
102
+ version: '0.87'
103
+ - !ruby/object:Gem::Dependency
104
+ name: rubocop-rspec
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '1.39'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '1.39'
89
117
  description: This gem adds a humanize method to EDTF::Decade, EDTF::Interval, EDTF::Set,
90
118
  EDTF::Season, EDTF::Unknown, and Date (ISO 8601 compliant) objects.
91
119
  email:
@@ -95,32 +123,46 @@ extensions: []
95
123
  extra_rdoc_files: []
96
124
  files:
97
125
  - LICENSE.txt
126
+ - config/locales/en.edtf.yml
127
+ - config/locales/fr.edtf.yml
98
128
  - lib/edtf-humanize.rb
99
129
  - lib/edtf/humanize.rb
100
130
  - lib/edtf/humanize/century.rb
101
131
  - lib/edtf/humanize/decade.rb
102
- - lib/edtf/humanize/formats.rb
103
132
  - lib/edtf/humanize/interval.rb
104
133
  - lib/edtf/humanize/iso_date.rb
134
+ - lib/edtf/humanize/language.rb
135
+ - lib/edtf/humanize/language/default.rb
136
+ - lib/edtf/humanize/language/default/century.rb
137
+ - lib/edtf/humanize/language/default/decade.rb
138
+ - lib/edtf/humanize/language/default/formats.rb
139
+ - lib/edtf/humanize/language/default/interval.rb
140
+ - lib/edtf/humanize/language/default/iso_date.rb
141
+ - lib/edtf/humanize/language/default/season.rb
142
+ - lib/edtf/humanize/language/default/set.rb
143
+ - lib/edtf/humanize/language/default/unknown.rb
144
+ - lib/edtf/humanize/language/english.rb
145
+ - lib/edtf/humanize/language/french.rb
105
146
  - lib/edtf/humanize/season.rb
106
147
  - lib/edtf/humanize/set.rb
107
148
  - lib/edtf/humanize/unknown.rb
108
149
  - lib/edtf/humanize/version.rb
109
- - spec/edtf_humanize_spec.rb
150
+ - spec/edtf_humanize_en_spec.rb
151
+ - spec/edtf_humanize_fr_spec.rb
110
152
  - spec/spec_helper.rb
111
153
  homepage: https://github.com/duke-libraries/edtf-humanize
112
154
  licenses:
113
155
  - BSD-3-Clause
114
156
  metadata: {}
115
- post_install_message:
157
+ post_install_message:
116
158
  rdoc_options: []
117
159
  require_paths:
118
160
  - lib
119
161
  required_ruby_version: !ruby/object:Gem::Requirement
120
162
  requirements:
121
- - - ">="
163
+ - - "~>"
122
164
  - !ruby/object:Gem::Version
123
- version: '0'
165
+ version: '2.4'
124
166
  required_rubygems_version: !ruby/object:Gem::Requirement
125
167
  requirements:
126
168
  - - ">="
@@ -128,9 +170,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
170
  version: '0'
129
171
  requirements: []
130
172
  rubygems_version: 3.0.6
131
- signing_key:
173
+ signing_key:
132
174
  specification_version: 4
133
175
  summary: This gem adds a humanize method to EDTF dates.
134
176
  test_files:
135
177
  - spec/spec_helper.rb
136
- - spec/edtf_humanize_spec.rb
178
+ - spec/edtf_humanize_fr_spec.rb
179
+ - spec/edtf_humanize_en_spec.rb
@@ -1,73 +0,0 @@
1
- module Edtf
2
- module Humanize
3
- module Formats
4
-
5
- private
6
-
7
- def simple_date_format date
8
- "#{apply_if_unspecified_year(date)}#{apply_if_uncertain(date)}"
9
- end
10
-
11
- def date_precision date
12
- if date.respond_to? :precision
13
- case date.precision
14
- when :day # 2010-10-25
15
- day_precision_format(date)
16
- when :month # 2010-10
17
- month_precision_format(date)
18
- when :year # 2010
19
- year_precision_format(date)
20
- end
21
- else
22
- date
23
- end
24
- end
25
-
26
- # October 5, 1995
27
- def day_precision_format date
28
- I18n.localize(date, format: Edtf::Humanize.configuration.day_precision_strftime_format)
29
- end
30
-
31
- # October 1995
32
- def month_precision_format date
33
- I18n.localize(date, format: Edtf::Humanize.configuration.month_precision_strftime_format)
34
- end
35
-
36
- # 1995
37
- def year_precision_format date
38
- date.strftime(Edtf::Humanize.configuration.year_precision_strftime_format)
39
- end
40
-
41
- # '1990~' => circa 1990
42
- def apply_if_approximate date
43
- if date.respond_to? :approximate?
44
- if date.approximate?
45
- Edtf::Humanize.configuration.approximate_date_prefix
46
- end
47
- end
48
- end
49
-
50
- # '1990?' => 1990?
51
- def apply_if_uncertain date
52
- if date.respond_to? :uncertain?
53
- if date.uncertain?
54
- Edtf::Humanize.configuration.uncertain_date_suffix
55
- end
56
- end
57
- end
58
-
59
- # '198u' => 198x
60
- def apply_if_unspecified_year date
61
- display = date_precision(date)
62
- if date.respond_to? :unspecified?
63
- if date.unspecified? :year
64
- year_substitute = date.year_precision.edtf.gsub(/u/, Edtf::Humanize.configuration.unspecified_digit_substitute)
65
- display.gsub!("#{date.year}", year_substitute)
66
- end
67
- end
68
- display
69
- end
70
-
71
- end
72
- end
73
- end
@@ -1,65 +0,0 @@
1
- require 'edtf-humanize'
2
-
3
- RSpec.describe Edtf::Humanize do
4
-
5
- it { is_expected.to be_a(Module) }
6
-
7
- context 'with a decade' do
8
- it 'should return a humanized decade string' do
9
- expect(Date.edtf('199x').humanize).to eq('1990s')
10
- end
11
- end
12
-
13
- context 'with a centrury' do
14
- it 'should return a humanized century string' do
15
- expect(Date.edtf('19xx').humanize).to eq('1900s')
16
- end
17
- end
18
-
19
- context 'with an interval' do
20
- it 'should return a humanized interval string' do
21
- expect(Date.edtf('1970/1980').humanize).to eq('1970 to 1980')
22
- end
23
- end
24
-
25
- context 'with an appoximate interval'
26
- it 'should return a humanized approximate interval string' do
27
- expect(Date.edtf('1970~/1980~').humanize).to eq('circa 1970 to circa 1980')
28
- end
29
-
30
- context 'with an iso date' do
31
- it 'should return a humanized ISO date string' do
32
- expect(Date.edtf('1975-07-01').humanize).to eq('July 1, 1975')
33
- end
34
- end
35
-
36
- context 'with an uncertain iso date' do
37
- it 'should return a humanized uncertain ISO date string' do
38
- expect(Date.edtf('1975?').humanize).to eq('1975?')
39
- end
40
- end
41
-
42
- context 'with an unspecfic year iso date' do
43
- it 'should return a humanized unspecified year ISO date string' do
44
- expect(Date.edtf('197u').humanize).to eq('197x')
45
- end
46
- end
47
-
48
- context 'with a season' do
49
- it 'should return a humanized season string' do
50
- expect(Date.edtf('1975-22').humanize).to eq('summer 1975')
51
- end
52
- end
53
-
54
- context 'with a set' do
55
- it 'should return a humanized set string' do
56
- expect(Date.edtf('[1980, 1981, 1983]').humanize).to eq('1980, 1981 or 1983')
57
- end
58
- end
59
-
60
- context 'with an unknown value' do
61
- it 'should return a humanized unknown string' do
62
- expect(Date.edtf('uuuu').humanize).to eq('unknown')
63
- end
64
- end
65
- end