edtf-humanize 2.3.0 → 2.3.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1d37dd3663889a9bcaa2a00392525eca76c61691705591c6c50f0ee8eacf9d8f
4
- data.tar.gz: de92c0782ba2cfa57b62d55a214ede47c8a6fa152cc14b7d38f6bde0c4bfc66b
3
+ metadata.gz: 1b98fb2e21907b61cc2ff0eb7d0176696b207234485a2d0ecd6bbfb6aef5b1c5
4
+ data.tar.gz: 25767f922e7197afb6fdb37a91e4f96cc570f3e1c445ee1fd3458331feee7222
5
5
  SHA512:
6
- metadata.gz: 47f4afa9029965ed3a620067218a4594559717f6eeae2ae42c5fe4ba985c6eae9d6be81fd06a150deabf8997c9d5fb10564d4915c0f725c3e0743c636df407cd
7
- data.tar.gz: 3180b6b54cc2b9011cfdef70259a4196721cc6894d0eab0258962020b0918e8bcfa2dc8b6744b6ba6f2f90f3f6a065039f214e39075490700597a70a6f3d372d
6
+ metadata.gz: e61cc357e93d6c9319fb79e759129e3a5bcdc3191201e22bd7aedf856d03ad46eed49ce8ae3dab5b28e948fc757992de02882d3b97022cd86b7400a21d406fe6
7
+ data.tar.gz: 8c86aca686a9e629e215c095ea2ed293593c337f6a681bcf8eb300694bdbdbf607f4a1ca734fe9ba739bda542e009035e57787755b50c3c176dbe45355580f1e
data/README.md ADDED
@@ -0,0 +1,184 @@
1
+ # edtf-humanize
2
+
3
+ [![CI](https://github.com/corylown/edtf-humanize/actions/workflows/ci.yml/badge.svg)](https://github.com/corylown/edtf-humanize/actions/workflows/ci.yml)
4
+
5
+ The EDTF-humanize gem adds a humanize method to EDTF::Decade, EDTF::Century, EDTF::Interval, EDTF::Set, EDTF::Season, EDTF::Unknown, and Date (ISO 8601 compliant) objects. It uses the [edtf-ruby](https://github.com/inukshuk/edtf-ruby) gem for parsing EDTF date strings into Date and EDTF objects.
6
+
7
+ See the [edtf-ruby project's documentation](https://github.com/inukshuk/edtf-ruby) for details about supported EDTF string formats and other implementation details.
8
+
9
+ This gem is used in production by Duke University Library's [digital repository](https://gitlab.oit.duke.edu/ddr/ddr-xenon/) to transform date metadata stored as Extended Date Time Format (EDTF) strings into human readable strings for display.
10
+
11
+
12
+ ## Installation
13
+
14
+ In a Rails application using Bundler
15
+
16
+ Add the following to your Gemfile:
17
+
18
+ ```
19
+ gem 'edtf-humanize'
20
+ ```
21
+
22
+ Then run:
23
+
24
+ ```
25
+ > bundle install
26
+ ```
27
+
28
+ To use in other contexts install the gem and require it:
29
+
30
+ ```
31
+ > gem install edtf-humanize
32
+ ```
33
+
34
+ ```
35
+ require 'edtf-humanize'
36
+ ```
37
+
38
+
39
+ ## Examples
40
+
41
+
42
+ ### Date (ISO 8601)
43
+
44
+ ```
45
+ > d = Date.edtf('1975-07-01')
46
+ => Tue, 01 Jul 1975
47
+ > d.humanize
48
+ => "July 1, 1975"
49
+ > d = Date.edtf('1981~')
50
+ => Thu, 01 Jan 1981
51
+ > d.humanize
52
+ => "circa 1981"
53
+ > d = Date.edtf('198u')
54
+ => Tue, 01 Jan 1980
55
+ > d.humanize
56
+ => "198x"
57
+ ```
58
+
59
+ ### EDTF::Season
60
+
61
+ ```
62
+ > d = Date.edtf('1975-22')
63
+ => #<EDTF::Season:0x0000000b6dd980 @year=1975, @season=:summer, @qualifier=nil>
64
+ > d.humanize
65
+ => "summer 1975"
66
+ ```
67
+
68
+ ### EDTF::Decade
69
+
70
+ ```
71
+ > d = Date.edtf('197x')
72
+ => #<EDTF::Decade:0x0000000b6fe798 @year=1970>
73
+ > d.humanize
74
+ => "1970s"
75
+ ```
76
+
77
+ ### EDTF::Century
78
+
79
+ ```
80
+ > d = Date.edtf('19xx')
81
+ => #<EDTF::Century:0x0000000b6fe798 @year=1900>
82
+ > d.humanize
83
+ => "1900s"
84
+ ```
85
+
86
+ ### EDTF::Interval
87
+
88
+ ```
89
+ > d = Date.edtf('1981/1985')
90
+ => #<EDTF::Interval:0x0000000ceeab18 @from=Thu, 01 Jan 1981, @to=Tue, 01 Jan 1985>
91
+ > d.humanize
92
+ => "1981 to 1985"
93
+ ```
94
+
95
+ ### EDTF::Set
96
+
97
+ ```
98
+ > d = Date.edtf('[1888, 1889, 1891]')
99
+ => #<EDTF::Set:0x0000000cef5450 @dates=#<Set: {Sun, 01 Jan 1888, Tue, 01 Jan 1889, Thu, 01 Jan 1891}>, @choice=true, @later=false, @earlier=false>
100
+ > d.humanize
101
+ => "1888, 1889 or 1891"
102
+ ```
103
+
104
+ ### EDTF::Unknown
105
+
106
+ ```
107
+ > d = Date.edtf('uuuu')
108
+ => #<EDTF::Unknown:0x0000000c04c688 @d=1>
109
+ > d.humanize
110
+ => "unknown"
111
+ ```
112
+
113
+ ## Internationalization
114
+
115
+ EDTF-humanize supports the use of I18n as well as language specific module overrides for more nuanced control. English, French, German, and Italian are supported.
116
+
117
+ Examples with current locale `:fr`:
118
+
119
+ ```
120
+ > Date.edtf('1975-24').humanize
121
+ => "hiver 1975"
122
+ > Date.edtf('20xx').humanize
123
+ => "XXIe siècle"
124
+ ```
125
+
126
+ ### Setting the locale
127
+
128
+ `humanize` uses the current `I18n.locale`. Set it globally or for a block:
129
+
130
+ ```ruby
131
+ I18n.locale = :de
132
+ Date.edtf('1975-07-01').humanize # => "1. Juli 1975"
133
+
134
+ I18n.with_locale(:fr) { Date.edtf('1975-07-01').humanize } # => "1 Juillet 1975"
135
+ ```
136
+
137
+ The supported locales are `:en`, `:fr`, `:de` and `:it`. Setting any other locale raises `I18n::InvalidLocale` unless you provide translations for it (see below).
138
+
139
+ ### Using outside Rails
140
+
141
+ No extra setup is needed beyond requiring the gem. `require 'edtf-humanize'` adds the gem's locale files to `I18n.load_path`:
142
+
143
+ ```ruby
144
+ require 'edtf-humanize'
145
+
146
+ I18n.locale = :it
147
+ Date.edtf('1975-22').humanize # => "estate 1975"
148
+ ```
149
+
150
+ Require `edtf-humanize`, not `edtf/humanize`. The latter loads the code without the locale files, so setting a non-English locale raises `I18n::InvalidLocale: :fr is not a valid locale`.
151
+
152
+ ### Customizing terms
153
+
154
+ All wording comes from the I18n keys in [`config/locales`](config/locales). To change a term, add your own locale file to `I18n.load_path` after requiring the gem; later files take precedence:
155
+
156
+ ```yaml
157
+ # config/locales/my_overrides.en.yml
158
+ en:
159
+ edtf:
160
+ terms:
161
+ approximate_date_prefix_year: "about "
162
+ ```
163
+
164
+ ```ruby
165
+ I18n.load_path << 'config/locales/my_overrides.en.yml'
166
+ I18n.reload! # only needed if translations were already used
167
+
168
+ Date.edtf('1981~').humanize # => "about 1981"
169
+ ```
170
+
171
+ Pull requests to add support for additional languages are welcome. You must add a new language module for the language and include the Default language module. A locales file with translations is also needed. The supporting files for French may be used as a reference for adding support for additional languages.:
172
+
173
+ ```
174
+ edtf-humanize/lib/edtf/humanize.rb
175
+ edtf-humanize/config/locales/fr.edtf.yml
176
+ edtf-humanize/lib/edtf/humanize/language/french.rb
177
+ edtf-humanize/spec/edtf/humanize_fr_spec.rb
178
+ ```
179
+
180
+ ## Contributions
181
+
182
+ Contributions, especially to add support for additional languages are welcome. Tests are expected and written using RSpec. Code style is enforced with Rubocop.
183
+
184
+
@@ -108,7 +108,9 @@ module Edtf
108
108
  I18n.t('edtf.terms.unspecified_digit_substitute',
109
109
  default: 'x')
110
110
  )
111
- display.gsub!(date.year.to_s, year_substitute)
111
+ # Match the zero-padded year as formatted, not year.to_s, which
112
+ # mismatches for years 0-999 and negative years ('00XX', '-01XX')
113
+ display.sub!(date.strftime('%Y'), year_substitute)
112
114
  end
113
115
  display
114
116
  end
@@ -19,6 +19,21 @@ module Edtf
19
19
 
20
20
  private
21
21
 
22
+ # EDTF::Season has no precision, so use the year-precision terms
23
+ # '1999-21~' => circa spring 1999
24
+ def apply_prefix_if_approximate(date)
25
+ return '' unless date.approximate?
26
+
27
+ I18n.t('edtf.terms.approximate_date_prefix_year', default: 'circa ')
28
+ end
29
+
30
+ # '1999-21~' => printemps 1999 environ
31
+ def apply_suffix_if_approximate(date)
32
+ return '' unless date.approximate?
33
+
34
+ I18n.t('edtf.terms.approximate_date_suffix_year', default: '')
35
+ end
36
+
22
37
  def translate_season(season)
23
38
  I18n.translate!("date.seasons.#{season}")
24
39
  rescue I18n::MissingTranslationData
@@ -35,7 +35,7 @@ module Edtf
35
35
  "#{apply_if_later(dates, index)}" \
36
36
  "#{apply_prefix_if_approximate(date)}" \
37
37
  "#{date_format(date)}" \
38
- "#{apply_suffix_if_approximate(date)}" \
38
+ "#{apply_suffix_if_approximate(date)}"
39
39
  end
40
40
  end
41
41
 
@@ -11,7 +11,8 @@ module Edtf
11
11
 
12
12
  def humanizer(date)
13
13
  "#{(date.year.abs / 100) + 1}." \
14
- "#{century_number_suffix}"
14
+ "#{century_number_suffix}" \
15
+ "#{century_sign_suffix(date)}"
15
16
  end
16
17
 
17
18
  private
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Edtf
4
4
  module Humanize
5
- VERSION = '2.3.0'
5
+ VERSION = '2.3.2'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: edtf-humanize
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cory Lown
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-12-17 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: activesupport
@@ -48,16 +47,22 @@ dependencies:
48
47
  name: roman
49
48
  requirement: !ruby/object:Gem::Requirement
50
49
  requirements:
51
- - - "~>"
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0.2'
53
+ - - "<"
52
54
  - !ruby/object:Gem::Version
53
- version: 0.2.0
55
+ version: '0.4'
54
56
  type: :runtime
55
57
  prerelease: false
56
58
  version_requirements: !ruby/object:Gem::Requirement
57
59
  requirements:
58
- - - "~>"
60
+ - - ">="
59
61
  - !ruby/object:Gem::Version
60
- version: 0.2.0
62
+ version: '0.2'
63
+ - - "<"
64
+ - !ruby/object:Gem::Version
65
+ version: '0.4'
61
66
  description: This gem adds a humanize method to EDTF::Decade, EDTF::Interval, EDTF::Set,
62
67
  EDTF::Season, EDTF::Unknown, and Date (ISO 8601 compliant) objects.
63
68
  email:
@@ -67,6 +72,7 @@ extensions: []
67
72
  extra_rdoc_files: []
68
73
  files:
69
74
  - LICENSE.txt
75
+ - README.md
70
76
  - config/locales/de.edtf.yml
71
77
  - config/locales/en.edtf.yml
72
78
  - config/locales/fr.edtf.yml
@@ -99,8 +105,9 @@ homepage: https://github.com/corylown/edtf-humanize
99
105
  licenses:
100
106
  - BSD-3-Clause
101
107
  metadata:
108
+ changelog_uri: https://github.com/corylown/edtf-humanize/releases
102
109
  rubygems_mfa_required: 'true'
103
- post_install_message:
110
+ source_code_uri: https://github.com/corylown/edtf-humanize
104
111
  rdoc_options: []
105
112
  require_paths:
106
113
  - lib
@@ -109,17 +116,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
109
116
  - - ">="
110
117
  - !ruby/object:Gem::Version
111
118
  version: '2.4'
112
- - - "<"
113
- - !ruby/object:Gem::Version
114
- version: '4'
115
119
  required_rubygems_version: !ruby/object:Gem::Requirement
116
120
  requirements:
117
121
  - - ">="
118
122
  - !ruby/object:Gem::Version
119
123
  version: '0'
120
124
  requirements: []
121
- rubygems_version: 3.4.19
122
- signing_key:
125
+ rubygems_version: 4.0.10
123
126
  specification_version: 4
124
127
  summary: This gem adds a humanize method to EDTF dates.
125
128
  test_files: []