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.
- checksums.yaml +4 -4
- data/config/locales/en.edtf.yml +44 -0
- data/config/locales/fr.edtf.yml +55 -0
- data/lib/edtf-humanize.rb +5 -0
- data/lib/edtf/humanize.rb +22 -45
- data/lib/edtf/humanize/century.rb +4 -4
- data/lib/edtf/humanize/decade.rb +4 -4
- data/lib/edtf/humanize/interval.rb +4 -21
- data/lib/edtf/humanize/iso_date.rb +4 -4
- data/lib/edtf/humanize/language.rb +13 -0
- data/lib/edtf/humanize/language/default.rb +17 -0
- data/lib/edtf/humanize/language/default/century.rb +20 -0
- data/lib/edtf/humanize/language/default/decade.rb +21 -0
- data/lib/edtf/humanize/language/default/formats.rb +115 -0
- data/lib/edtf/humanize/language/default/interval.rb +132 -0
- data/lib/edtf/humanize/language/default/iso_date.rb +21 -0
- data/lib/edtf/humanize/language/default/season.rb +30 -0
- data/lib/edtf/humanize/language/default/set.rb +78 -0
- data/lib/edtf/humanize/language/default/unknown.rb +17 -0
- data/lib/edtf/humanize/language/english.rb +11 -0
- data/lib/edtf/humanize/language/french.rb +36 -0
- data/lib/edtf/humanize/season.rb +4 -16
- data/lib/edtf/humanize/set.rb +4 -33
- data/lib/edtf/humanize/unknown.rb +5 -3
- data/lib/edtf/humanize/version.rb +3 -1
- data/spec/edtf_humanize_en_spec.rb +102 -0
- data/spec/edtf_humanize_fr_spec.rb +110 -0
- data/spec/spec_helper.rb +2 -0
- metadata +63 -20
- data/lib/edtf/humanize/formats.rb +0 -73
- data/spec/edtf_humanize_spec.rb +0 -65
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dcd453eb435bc411afc324c1fe00324311b91ad5feb2559cf44f6e7df30dc610
|
4
|
+
data.tar.gz: '019a07057a906c4d45fe710c7034bab92a63fb86241ffca22858049c51bb4085'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a95e5aba3f7e614f88f66eeb33c7ea6046b0a977fc39b87c638de2cad6e7ffad4e751c68392da4533faaec3f5ba40ba44c6792267f07beed5c350a48479163c
|
7
|
+
data.tar.gz: 31f9e3b7d806b3a095444264e2f56302bfcbca868e88c5690d8ddbf5a119a773a5a4f18109534576ba3ec3b88d13129e9cc5835877ba980de03f7f6571333c85
|
@@ -0,0 +1,44 @@
|
|
1
|
+
en:
|
2
|
+
edtf:
|
3
|
+
terms:
|
4
|
+
approximate_date_prefix_day: "circa "
|
5
|
+
approximate_date_prefix_month: "circa "
|
6
|
+
approximate_date_prefix_year: "circa "
|
7
|
+
approximate_date_suffix_day: ""
|
8
|
+
approximate_date_suffix_month: ""
|
9
|
+
approximate_date_suffix_year: ""
|
10
|
+
century_suffix: "s"
|
11
|
+
decade_prefix: ""
|
12
|
+
decade_suffix: "s"
|
13
|
+
interval_prefix_day: ""
|
14
|
+
interval_prefix_month: ""
|
15
|
+
interval_prefix_year: ""
|
16
|
+
interval_connector_approximate: " to "
|
17
|
+
interval_connector_day: " to "
|
18
|
+
interval_connector_open: " to "
|
19
|
+
interval_connector_month: " to "
|
20
|
+
interval_connector_year: " to "
|
21
|
+
interval_unspecified_suffix: "s"
|
22
|
+
open_start_interval_with_day: "until %{date}"
|
23
|
+
open_start_interval_with_month: "until %{date}"
|
24
|
+
open_start_interval_with_year: "until %{date}"
|
25
|
+
open_end_interval_with_day: "since %{date}"
|
26
|
+
open_end_interval_with_month: "since %{date}"
|
27
|
+
open_end_interval_with_year: "since %{date}"
|
28
|
+
set_dates_connector_exclusive: ", "
|
29
|
+
set_dates_connector_inclusive: ", "
|
30
|
+
set_earlier_prefix_exclusive: 'on or before '
|
31
|
+
set_earlier_prefix_inclusive: 'on and before '
|
32
|
+
set_last_date_connector_exclusive: " or "
|
33
|
+
set_last_date_connector_inclusive: " and "
|
34
|
+
set_later_prefix_exclusive: 'on or after '
|
35
|
+
set_later_prefix_inclusive: 'on and after '
|
36
|
+
set_two_dates_connector_exclusive: " or "
|
37
|
+
set_two_dates_connector_inclusive: " and "
|
38
|
+
uncertain_date_suffix: "?"
|
39
|
+
unknown: 'unknown'
|
40
|
+
unspecified_digit_substitute: "x"
|
41
|
+
formats:
|
42
|
+
day_precision_strftime_format: "%B %-d, %Y"
|
43
|
+
month_precision_strftime_format: "%B %Y"
|
44
|
+
year_precision_strftime_format: "%Y"
|
@@ -0,0 +1,55 @@
|
|
1
|
+
fr:
|
2
|
+
date:
|
3
|
+
day_names: [Dimanche, Lundi, Mardi, Mercredi, Jeudi, Vendredi, Samedi]
|
4
|
+
abbr_day_names: [Dim, Lun, Mar, Mer, Jeu, Ven, Sam]
|
5
|
+
# Don't forget the nil at the beginning; there's no such thing as a 0th month
|
6
|
+
month_names: [~, Janvier, Février, Mars, Avril, Mai, Juin, Juillet, Août, Septembre, Octobre, Novembre, Decembre]
|
7
|
+
abbr_month_names: [~, Jan, Fev, Mar, Avr, Mai, Jun, Jul, Aou, Sep, Oct, Nov, Dec]
|
8
|
+
seasons:
|
9
|
+
spring: "printemps"
|
10
|
+
summer: "été"
|
11
|
+
autumn: "automne"
|
12
|
+
winter: "hiver"
|
13
|
+
edtf:
|
14
|
+
terms:
|
15
|
+
approximate_date_prefix_day: ""
|
16
|
+
approximate_date_prefix_month: ""
|
17
|
+
approximate_date_prefix_year: ""
|
18
|
+
approximate_date_suffix_day: " environ"
|
19
|
+
approximate_date_suffix_month: " environ"
|
20
|
+
approximate_date_suffix_year: " environ"
|
21
|
+
decade_prefix: "Les années "
|
22
|
+
decade_suffix: ""
|
23
|
+
century_suffix: ""
|
24
|
+
interval_prefix_day: "Du "
|
25
|
+
interval_prefix_month: "De "
|
26
|
+
interval_prefix_year: "De "
|
27
|
+
interval_connector_approximate: " à "
|
28
|
+
interval_connector_open: " à "
|
29
|
+
interval_connector_day: " au "
|
30
|
+
interval_connector_month: " à "
|
31
|
+
interval_connector_year: " à "
|
32
|
+
interval_unspecified_suffix: "s"
|
33
|
+
open_start_interval_with_day: "Jusqu'au %{date}"
|
34
|
+
open_start_interval_with_month: "Jusqu'en %{date}"
|
35
|
+
open_start_interval_with_year: "Jusqu'en %{date}"
|
36
|
+
open_end_interval_with_day: "Depuis le %{date}"
|
37
|
+
open_end_interval_with_month: "Depuis %{date}"
|
38
|
+
open_end_interval_with_year: "Depuis %{date}"
|
39
|
+
set_dates_connector_exclusive: ", "
|
40
|
+
set_dates_connector_inclusive: ", "
|
41
|
+
set_earlier_prefix_exclusive: 'Le ou avant '
|
42
|
+
set_earlier_prefix_inclusive: 'Le et avant '
|
43
|
+
set_last_date_connector_exclusive: " ou "
|
44
|
+
set_last_date_connector_inclusive: " et "
|
45
|
+
set_later_prefix_exclusive: 'Le ou après '
|
46
|
+
set_later_prefix_inclusive: 'Le et après '
|
47
|
+
set_two_dates_connector_exclusive: " ou "
|
48
|
+
set_two_dates_connector_inclusive: " et "
|
49
|
+
uncertain_date_suffix: "?"
|
50
|
+
unknown: 'Inconnue'
|
51
|
+
unspecified_digit_substitute: "x"
|
52
|
+
formats:
|
53
|
+
day_precision_strftime_format: "%-d %B %Y"
|
54
|
+
month_precision_strftime_format: "%B %Y"
|
55
|
+
year_precision_strftime_format: "%Y"
|
data/lib/edtf-humanize.rb
CHANGED
data/lib/edtf/humanize.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Edtf
|
2
4
|
module Humanize
|
3
|
-
|
4
5
|
require 'edtf'
|
5
6
|
|
6
|
-
require 'edtf/humanize/
|
7
|
+
require 'edtf/humanize/language'
|
7
8
|
require 'edtf/humanize/decade'
|
8
9
|
require 'edtf/humanize/century'
|
9
10
|
require 'edtf/humanize/season'
|
@@ -11,6 +12,17 @@ module Edtf
|
|
11
12
|
require 'edtf/humanize/set'
|
12
13
|
require 'edtf/humanize/unknown'
|
13
14
|
require 'edtf/humanize/iso_date'
|
15
|
+
require 'edtf/humanize/language/default/formats'
|
16
|
+
require 'edtf/humanize/language/default/decade'
|
17
|
+
require 'edtf/humanize/language/default/century'
|
18
|
+
require 'edtf/humanize/language/default/season'
|
19
|
+
require 'edtf/humanize/language/default/interval'
|
20
|
+
require 'edtf/humanize/language/default/set'
|
21
|
+
require 'edtf/humanize/language/default/unknown'
|
22
|
+
require 'edtf/humanize/language/default/iso_date'
|
23
|
+
require 'edtf/humanize/language/default'
|
24
|
+
require 'edtf/humanize/language/english'
|
25
|
+
require 'edtf/humanize/language/french'
|
14
26
|
|
15
27
|
EDTF::Decade.include Edtf::Humanize::Decade
|
16
28
|
EDTF::Century.include Edtf::Humanize::Century
|
@@ -20,7 +32,6 @@ module Edtf
|
|
20
32
|
EDTF::Unknown.include Edtf::Humanize::Unknown
|
21
33
|
Date.include Edtf::Humanize::IsoDate
|
22
34
|
|
23
|
-
|
24
35
|
def self.configuration
|
25
36
|
@configuration ||= Configuration.new
|
26
37
|
end
|
@@ -34,51 +45,17 @@ module Edtf
|
|
34
45
|
end
|
35
46
|
|
36
47
|
class Configuration
|
37
|
-
|
38
|
-
attr_accessor :day_precision_strftime_format,
|
39
|
-
:month_precision_strftime_format,
|
40
|
-
:year_precision_strftime_format,
|
41
|
-
:approximate_date_prefix,
|
42
|
-
:uncertain_date_suffix,
|
43
|
-
:decade_suffix,
|
44
|
-
:century_suffix,
|
45
|
-
:unspecified_digit_substitute,
|
46
|
-
:interval_connector,
|
47
|
-
:interval_unspecified_suffix,
|
48
|
-
:set_dates_connector,
|
49
|
-
:set_last_date_connector,
|
50
|
-
:set_two_dates_connector,
|
51
|
-
:set_earlier_prefix,
|
52
|
-
:set_later_prefix,
|
53
|
-
:unknown
|
54
|
-
|
55
48
|
def initialize
|
56
|
-
@
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
@uncertain_date_suffix = "?"
|
63
|
-
|
64
|
-
@decade_suffix = "s"
|
65
|
-
@century_suffix = "s"
|
66
|
-
|
67
|
-
@unspecified_digit_substitute = "x"
|
68
|
-
|
69
|
-
@interval_connector = " to "
|
70
|
-
@interval_unspecified_suffix = "s"
|
71
|
-
|
72
|
-
@set_dates_connector = ", "
|
73
|
-
@set_last_date_connector = " or "
|
74
|
-
@set_two_dates_connector = " or "
|
75
|
-
@set_earlier_prefix = "on or before "
|
76
|
-
@set_later_prefix = "on or after "
|
77
|
-
|
78
|
-
@unknown = "unknown"
|
49
|
+
@language_strategies = {
|
50
|
+
default: Edtf::Humanize::Language::Default,
|
51
|
+
en: Edtf::Humanize::Language::English,
|
52
|
+
fr: Edtf::Humanize::Language::French
|
53
|
+
}
|
79
54
|
end
|
80
55
|
|
56
|
+
def language_strategy(language)
|
57
|
+
@language_strategies[language.to_sym] || @language_strategies[:default]
|
58
|
+
end
|
81
59
|
end
|
82
|
-
|
83
60
|
end
|
84
61
|
end
|
@@ -1,13 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Edtf
|
2
4
|
module Humanize
|
3
5
|
module Century
|
4
|
-
|
5
|
-
include Edtf::Humanize::Formats
|
6
|
+
include Edtf::Humanize::Language
|
6
7
|
|
7
8
|
def humanize
|
8
|
-
|
9
|
+
language_strategy::Century.humanizer(self)
|
9
10
|
end
|
10
|
-
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
data/lib/edtf/humanize/decade.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Edtf
|
2
4
|
module Humanize
|
3
5
|
module Decade
|
4
|
-
|
5
|
-
include Edtf::Humanize::Formats
|
6
|
+
include Edtf::Humanize::Language
|
6
7
|
|
7
8
|
def humanize
|
8
|
-
|
9
|
+
language_strategy::Decade.humanizer(self)
|
9
10
|
end
|
10
|
-
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
@@ -1,30 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Edtf
|
2
4
|
module Humanize
|
3
5
|
module Interval
|
4
|
-
|
5
|
-
include Edtf::Humanize::Formats
|
6
|
+
include Edtf::Humanize::Language
|
6
7
|
|
7
8
|
def humanize
|
8
|
-
|
9
|
-
"#{simple_date_format(self.from)}"\
|
10
|
-
"#{Edtf::Humanize.configuration.interval_connector}"\
|
11
|
-
"#{apply_if_approximate(self.to)}"\
|
12
|
-
"#{simple_date_format(self.to)}"
|
13
|
-
end
|
14
|
-
|
15
|
-
private
|
16
|
-
|
17
|
-
# '198u/199u' => 1980s to 1990s
|
18
|
-
def apply_if_unspecified_year date
|
19
|
-
display = date_precision(date)
|
20
|
-
if date.respond_to? :unspecified?
|
21
|
-
if date.unspecified? :year
|
22
|
-
display << Edtf::Humanize.configuration.interval_unspecified_suffix
|
23
|
-
end
|
24
|
-
end
|
25
|
-
display
|
9
|
+
language_strategy::Interval.humanizer(self)
|
26
10
|
end
|
27
|
-
|
28
11
|
end
|
29
12
|
end
|
30
13
|
end
|
@@ -1,13 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Edtf
|
2
4
|
module Humanize
|
3
5
|
module IsoDate
|
4
|
-
|
5
|
-
include Edtf::Humanize::Formats
|
6
|
+
include Edtf::Humanize::Language
|
6
7
|
|
7
8
|
def humanize
|
8
|
-
|
9
|
+
language_strategy::IsoDate.humanizer(self)
|
9
10
|
end
|
10
|
-
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Edtf
|
4
|
+
module Humanize
|
5
|
+
module Language
|
6
|
+
module Default
|
7
|
+
include Century
|
8
|
+
include Decade
|
9
|
+
include Interval
|
10
|
+
include IsoDate
|
11
|
+
include Season
|
12
|
+
include Set
|
13
|
+
include Unknown
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Edtf
|
4
|
+
module Humanize
|
5
|
+
module Language
|
6
|
+
module Default
|
7
|
+
module Century
|
8
|
+
include Edtf::Humanize::Language::Default::Formats
|
9
|
+
|
10
|
+
extend self
|
11
|
+
|
12
|
+
def humanizer(date)
|
13
|
+
"#{date.begin.year}" \
|
14
|
+
"#{I18n.t('edtf.terms.century_suffix', default: 's')}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Edtf
|
4
|
+
module Humanize
|
5
|
+
module Language
|
6
|
+
module Default
|
7
|
+
module Decade
|
8
|
+
include Edtf::Humanize::Language::Default::Formats
|
9
|
+
|
10
|
+
extend self
|
11
|
+
|
12
|
+
def humanizer(date)
|
13
|
+
"#{I18n.t('edtf.terms.decade_prefix', default: '')}" \
|
14
|
+
"#{date.begin.year}" \
|
15
|
+
"#{I18n.t('edtf.terms.decade_suffix', default: 's')}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Edtf
|
4
|
+
module Humanize
|
5
|
+
module Language
|
6
|
+
module Default
|
7
|
+
module Formats
|
8
|
+
extend self
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def date_format(date)
|
13
|
+
"#{apply_if_unspecified_year(date)}#{apply_if_uncertain(date)}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def date_precision(date)
|
17
|
+
if date.respond_to? :precision
|
18
|
+
case date.precision
|
19
|
+
when :day # 2010-10-25
|
20
|
+
day_precision_format(date)
|
21
|
+
when :month # 2010-10
|
22
|
+
month_precision_format(date)
|
23
|
+
when :year # 2010
|
24
|
+
year_precision_format(date)
|
25
|
+
end
|
26
|
+
else
|
27
|
+
date
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# October 5, 1995
|
32
|
+
def day_precision_format(date)
|
33
|
+
I18n.localize(
|
34
|
+
date,
|
35
|
+
format: I18n.t('edtf.formats.day_precision_strftime_format',
|
36
|
+
default: '%B %-d, %Y')
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
# October 1995
|
41
|
+
def month_precision_format(date)
|
42
|
+
I18n.localize(
|
43
|
+
date,
|
44
|
+
format: I18n.t('edtf.formats.month_precision_strftime_format',
|
45
|
+
default: '%B %Y')
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
# 1995
|
50
|
+
def year_precision_format(date)
|
51
|
+
date.strftime(I18n.t('edtf.formats.year_precision_strftime_format',
|
52
|
+
default: '%Y'))
|
53
|
+
end
|
54
|
+
|
55
|
+
# '1990~' => circa 1990
|
56
|
+
def apply_prefix_if_approximate(date)
|
57
|
+
return unless date.respond_to?(:approximate?) && date.approximate?
|
58
|
+
|
59
|
+
case date.precision
|
60
|
+
when :year
|
61
|
+
I18n.t('edtf.terms.approximate_date_prefix_year',
|
62
|
+
default: 'circa ')
|
63
|
+
when :month
|
64
|
+
I18n.t('edtf.terms.approximate_date_prefix_month',
|
65
|
+
default: 'circa ')
|
66
|
+
when :day
|
67
|
+
I18n.t('edtf.terms.approximate_date_prefix_day',
|
68
|
+
default: 'circa ')
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# '1990~' => 1990 environ
|
73
|
+
def apply_suffix_if_approximate(date)
|
74
|
+
return '' unless date.respond_to?(:approximate?) &&
|
75
|
+
date.approximate?
|
76
|
+
|
77
|
+
case date.precision
|
78
|
+
when :year
|
79
|
+
I18n.t('edtf.terms.approximate_date_suffix_year', default: '')
|
80
|
+
when :month
|
81
|
+
I18n.t('edtf.terms.approximate_date_suffix_month', default: '')
|
82
|
+
when :day
|
83
|
+
I18n.t('edtf.terms.approximate_date_suffix_day', default: '')
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# '1990?' => 1990?
|
88
|
+
def apply_if_uncertain(date)
|
89
|
+
return '' unless date.respond_to?(:uncertain?) && date.uncertain?
|
90
|
+
|
91
|
+
I18n.t('edtf.terms.uncertain_date_suffix', default: '?')
|
92
|
+
end
|
93
|
+
|
94
|
+
# '198u' => 198x
|
95
|
+
def apply_if_unspecified_year(date)
|
96
|
+
display = date_precision(date)
|
97
|
+
if date.respond_to? :unspecified?
|
98
|
+
if date.unspecified? :year
|
99
|
+
year_substitute =
|
100
|
+
date.year_precision.edtf.gsub(
|
101
|
+
/u/,
|
102
|
+
I18n.t('edtf.terms.unspecified_digit_substitute',
|
103
|
+
default: 'x')
|
104
|
+
)
|
105
|
+
display.gsub!(date.year.to_s, year_substitute)
|
106
|
+
end
|
107
|
+
elsif date
|
108
|
+
end
|
109
|
+
display
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|