edtf-humanize 1.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/config/locales/en.edtf.yml +44 -0
  3. data/config/locales/fr.edtf.yml +55 -0
  4. data/config/locales/it.edtf.yml +55 -0
  5. data/lib/edtf/humanize/century.rb +4 -4
  6. data/lib/edtf/humanize/decade.rb +4 -4
  7. data/lib/edtf/humanize/interval.rb +4 -21
  8. data/lib/edtf/humanize/iso_date.rb +4 -4
  9. data/lib/edtf/humanize/language/default/century.rb +20 -0
  10. data/lib/edtf/humanize/language/default/decade.rb +21 -0
  11. data/lib/edtf/humanize/language/default/formats.rb +112 -0
  12. data/lib/edtf/humanize/language/default/interval.rb +132 -0
  13. data/lib/edtf/humanize/language/default/iso_date.rb +21 -0
  14. data/lib/edtf/humanize/language/default/season.rb +30 -0
  15. data/lib/edtf/humanize/language/default/set.rb +78 -0
  16. data/lib/edtf/humanize/language/default/unknown.rb +17 -0
  17. data/lib/edtf/humanize/language/default.rb +17 -0
  18. data/lib/edtf/humanize/language/english.rb +11 -0
  19. data/lib/edtf/humanize/language/french.rb +36 -0
  20. data/lib/edtf/humanize/language/italian.rb +34 -0
  21. data/lib/edtf/humanize/language.rb +13 -0
  22. data/lib/edtf/humanize/season.rb +4 -16
  23. data/lib/edtf/humanize/set.rb +4 -33
  24. data/lib/edtf/humanize/unknown.rb +5 -3
  25. data/lib/edtf/humanize/version.rb +3 -1
  26. data/lib/edtf/humanize.rb +24 -45
  27. data/lib/edtf-humanize.rb +5 -0
  28. data/spec/edtf_humanize_en_spec.rb +102 -0
  29. data/spec/edtf_humanize_fr_spec.rb +110 -0
  30. data/spec/edtf_humanize_it_spec.rb +110 -0
  31. data/spec/spec_helper.rb +2 -0
  32. metadata +70 -20
  33. data/lib/edtf/humanize/formats.rb +0 -73
  34. data/spec/edtf_humanize_spec.rb +0 -65
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 370eca8ed68c9afdd06117f0e584f82f2f48eac108a1113b77ce91355844bcba
4
- data.tar.gz: 608b950683ce5117a1bcb9fe63380fc99ce705b53184f8e68c6e6a545527bbf7
3
+ metadata.gz: 4d1b42abe59756665b608da4635e8766f78fb44ac2e658e14365141bf919eae9
4
+ data.tar.gz: f7a583e56c886eee461568fd2deacbd4769221b48b1f5e6b6f9b2ed68b08420c
5
5
  SHA512:
6
- metadata.gz: 4093df048a06504a30c04a8960ed6e253bb39a3d5d0015ac6f791287515ea9d2c800c0d04bf1e2834b5da2757243b47a1ab78589c5b259e7b9a7bd58ad4d2991
7
- data.tar.gz: 6946c6594d3149788cbfc4ec50f770d450b3716817d7c8ad4c73c0ad58cd3a3b535436b1e373ccf998528d9ebdd4eb9faed24f42898da2d5de58b9ca9023bd7e
6
+ metadata.gz: e7d3799ba863355aefa8afd5fdd09f20bc796cea31609d2015979b36f175ccff9a998019b62901c71d0873ca48dc03c0405f47fce7dd049d2ac801fc763d74f3
7
+ data.tar.gz: 6233da61c4a069e473336c229cd117e479ce1037d10d789506a32565ff4abed04740ce9fa59df1f8be772aaaa62447e58e9b422f6d72ed8778c9e2a6416e0035
@@ -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"
@@ -0,0 +1,55 @@
1
+ it:
2
+ date:
3
+ day_names: [domenica, lunedì, martedì, mercoledì, giovedì, venerdì, sabato]
4
+ abbr_day_names: [dom, lun, mar, mer, gio, ven, sab]
5
+ # Don't forget the nil at the beginning; there's no such thing as a 0th month
6
+ month_names: [~, gennaio, febbraio, marzo, aprile, maggio, giugno, luglio, agosto, settembre, ottobre, novembre, dicembre]
7
+ abbr_month_names: [~, gen, feb, mar, apr, mag, giu, lug, ago, set, ott, nov, dic]
8
+ seasons:
9
+ spring: "primavera"
10
+ summer: "estate"
11
+ autumn: "autunno"
12
+ winter: "inverno"
13
+ edtf:
14
+ terms:
15
+ approximate_date_prefix_day: "circa "
16
+ approximate_date_prefix_month: "circa "
17
+ approximate_date_prefix_year: "circa "
18
+ approximate_date_suffix_day: ""
19
+ approximate_date_suffix_month: ""
20
+ approximate_date_suffix_year: ""
21
+ decade_prefix: "anni "
22
+ decade_suffix: ""
23
+ century_suffix: ""
24
+ interval_prefix_day: ""
25
+ interval_prefix_month: ""
26
+ interval_prefix_year: ""
27
+ interval_connector_approximate: " - "
28
+ interval_connector_open: " - "
29
+ interval_connector_day: " - "
30
+ interval_connector_month: " - "
31
+ interval_connector_year: " - "
32
+ interval_unspecified_suffix: ""
33
+ open_start_interval_with_day: "fino a %{date}"
34
+ open_start_interval_with_month: "fino a %{date}"
35
+ open_start_interval_with_year: "fino a %{date}"
36
+ open_end_interval_with_day: "%{date} - "
37
+ open_end_interval_with_month: "%{date} - "
38
+ open_end_interval_with_year: "%{date} - "
39
+ set_dates_connector_exclusive: ", "
40
+ set_dates_connector_inclusive: ", "
41
+ set_earlier_prefix_exclusive: "prima di "
42
+ set_earlier_prefix_inclusive: "prima di "
43
+ set_last_date_connector_exclusive: " o "
44
+ set_last_date_connector_inclusive: " e "
45
+ set_later_prefix_exclusive: "dopo "
46
+ set_later_prefix_inclusive: "dopo "
47
+ set_two_dates_connector_exclusive: " o "
48
+ set_two_dates_connector_inclusive: " e "
49
+ uncertain_date_suffix: " ?"
50
+ unknown: "data sconosciuta"
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"
@@ -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
- "#{self.begin.year}#{Edtf::Humanize.configuration.century_suffix}"
9
+ language_strategy::Century.humanizer(self)
9
10
  end
10
-
11
11
  end
12
12
  end
13
13
  end
@@ -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
- "#{self.begin.year}#{Edtf::Humanize.configuration.decade_suffix}"
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
- "#{apply_if_approximate(self.from)}"\
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
- "#{apply_if_approximate(self)}#{simple_date_format(self)}"
9
+ language_strategy::IsoDate.humanizer(self)
9
10
  end
10
-
11
11
  end
12
12
  end
13
13
  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,112 @@
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?) && date.unspecified?(:year)
98
+ year_substitute =
99
+ date.year_precision.edtf.gsub(
100
+ /u/,
101
+ I18n.t('edtf.terms.unspecified_digit_substitute',
102
+ default: 'x')
103
+ )
104
+ display.gsub!(date.year.to_s, year_substitute)
105
+ end
106
+ display
107
+ end
108
+ end
109
+ end
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,132 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Edtf
4
+ module Humanize
5
+ module Language
6
+ module Default
7
+ module Interval
8
+ include Edtf::Humanize::Language::Default::Formats
9
+
10
+ extend self
11
+
12
+ def humanizer(date)
13
+ if date.from == :open || date.to == :open
14
+ open_interval(date)
15
+ else
16
+ "#{interval_prefix(date)}" \
17
+ "#{formatted_date(date.from)}" \
18
+ "#{interval_connector(date)}" \
19
+ "#{formatted_date(date.to)}"
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def open_interval(date)
26
+ if date.from == :open
27
+ open_start_interval(formatted_date: formatted_date(date.to),
28
+ precision: date.to.precision)
29
+ elsif date.to == :open
30
+ open_end_interval(formatted_date: formatted_date(date.from),
31
+ precision: date.from.precision)
32
+ end
33
+ end
34
+
35
+ # open/1980 => Jusqu'en 1980
36
+ def open_start_interval(formatted_date:, precision:)
37
+ case precision
38
+ when :year
39
+ I18n.t('edtf.terms.open_start_interval_with_year',
40
+ date: formatted_date,
41
+ default: "until #{formatted_date}")
42
+ when :month
43
+ I18n.t('edtf.terms.open_start_interval_with_month',
44
+ date: formatted_date,
45
+ default: "until #{formatted_date}")
46
+ when :day
47
+ I18n.t('edtf.terms.open_start_interval_with_day',
48
+ date: formatted_date,
49
+ default: "until #{formatted_date}")
50
+ end
51
+ end
52
+
53
+ # 1980/open => Depuis 1980
54
+ def open_end_interval(formatted_date:, precision:)
55
+ case precision
56
+ when :year
57
+ I18n.t('edtf.terms.open_end_interval_with_year',
58
+ date: formatted_date,
59
+ default: "since #{formatted_date}")
60
+ when :month
61
+ I18n.t('edtf.terms.open_end_interval_with_month',
62
+ date: formatted_date,
63
+ default: "since #{formatted_date}")
64
+ when :day
65
+ I18n.t('edtf.terms.open_end_interval_with_day',
66
+ date: formatted_date,
67
+ default: "since #{formatted_date}")
68
+ end
69
+ end
70
+
71
+ def formatted_date(date)
72
+ "#{apply_prefix_if_approximate(date)}" \
73
+ "#{date_format(date)}" \
74
+ "#{apply_suffix_if_approximate(date)}"
75
+ end
76
+
77
+ def interval_prefix(date)
78
+ case date.from.precision
79
+ when :year
80
+ I18n.t('edtf.terms.interval_prefix_year', default: '')
81
+ when :month
82
+ I18n.t('edtf.terms.interval_prefix_month', default: '')
83
+ when :day
84
+ I18n.t('edtf.terms.interval_prefix_day', default: '')
85
+ end
86
+ end
87
+
88
+ def interval_connector(date)
89
+ return interval_connector_open if date.to == :open
90
+
91
+ return interval_connector_approx if date.to.approximate.day ||
92
+ date.to.approximate.month ||
93
+ date.to.approximate.year
94
+
95
+ interval_connector_other(date)
96
+ end
97
+
98
+ def interval_connector_open
99
+ I18n.t('edtf.terms.interval_connector_open')
100
+ end
101
+
102
+ def interval_connector_approx
103
+ I18n.t('edtf.terms.interval_connector_approximate',
104
+ default: ' to ')
105
+ end
106
+
107
+ def interval_connector_other(date)
108
+ case date.to.precision
109
+ when :year
110
+ I18n.t('edtf.terms.interval_connector_year', default: ' to ')
111
+ when :month
112
+ I18n.t('edtf.terms.interval_connector_month', default: ' to ')
113
+ when :day
114
+ I18n.t('edtf.terms.interval_connector_day', default: ' to ')
115
+ end
116
+ end
117
+
118
+ # '198u/199u' => 1980s to 1990s
119
+ def apply_if_unspecified_year(date)
120
+ if date.respond_to?(:unspecified?) && date.unspecified?(:year)
121
+ return "#{date_precision(date)}" \
122
+ "#{I18n.t('edtf.terms.interval_unspecified_suffix',
123
+ default: 's')}"
124
+ end
125
+
126
+ date_precision(date)
127
+ end
128
+ end
129
+ end
130
+ end
131
+ end
132
+ 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 IsoDate
8
+ include Edtf::Humanize::Language::Default::Formats
9
+
10
+ extend self
11
+
12
+ def humanizer(date)
13
+ "#{apply_prefix_if_approximate(date)}" \
14
+ "#{date_format(date)}" \
15
+ "#{apply_suffix_if_approximate(date)}"
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Edtf
4
+ module Humanize
5
+ module Language
6
+ module Default
7
+ module Season
8
+ include Edtf::Humanize::Language::Default::Formats
9
+
10
+ extend self
11
+
12
+ def humanizer(date)
13
+ "#{apply_prefix_if_approximate(date)}"\
14
+ "#{translate_season(date.season)} #{date.year}"\
15
+ "#{apply_suffix_if_approximate(date)}"\
16
+ "#{apply_if_uncertain(date)}"
17
+ end
18
+
19
+ private
20
+
21
+ def translate_season(season)
22
+ I18n.translate!("date.seasons.#{season}")
23
+ rescue I18n::MissingTranslationData
24
+ season
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Edtf
4
+ module Humanize
5
+ module Language
6
+ module Default
7
+ module Set
8
+ include Edtf::Humanize::Language::Default::Formats
9
+
10
+ extend self
11
+
12
+ def humanizer(date)
13
+ format_set_entries(date).to_sentence(
14
+ words_connector:
15
+ I18n.t("edtf.terms.set_dates_connector_#{mode(date)}",
16
+ default: ', '),
17
+ last_word_connector:
18
+ I18n.t("edtf.terms.set_last_date_connector_#{mode(date)}",
19
+ default: default_word_connector(date)),
20
+ two_words_connector:
21
+ I18n.t("edtf.terms.set_two_dates_connector_#{mode(date)}",
22
+ default: default_word_connector(date))
23
+ )
24
+ end
25
+
26
+ private
27
+
28
+ def default_word_connector(date)
29
+ mode(date) == 'inclusive' ? ' and ' : ' or '
30
+ end
31
+
32
+ def format_set_entries(dates)
33
+ dates.entries.map.with_index do |date, index|
34
+ "#{apply_if_earlier(dates, index)}"\
35
+ "#{apply_if_later(dates, index)}"\
36
+ "#{apply_prefix_if_approximate(date)}"\
37
+ "#{date_format(date)}"\
38
+ "#{apply_suffix_if_approximate(date)}"\
39
+ end
40
+ end
41
+
42
+ # '[..1760-12-03]' => on or before December 3, 1760
43
+ def apply_if_earlier(dates, index)
44
+ return earlier_prefix(dates) if dates.earlier? && index.zero?
45
+ end
46
+
47
+ def earlier_prefix(dates)
48
+ I18n.t("edtf.terms.set_earlier_prefix_#{mode(dates)}",
49
+ default: earlier_prefix_default(dates))
50
+ end
51
+
52
+ def earlier_prefix_default(dates)
53
+ mode(dates) == 'inclusive' ? 'on and before ' : 'on or before '
54
+ end
55
+
56
+ # '[1760-12..]' => on or after December 1760
57
+ def apply_if_later(dates, index)
58
+ return later_prefix(dates) if dates.later? &&
59
+ (index + 1) == dates.size
60
+ end
61
+
62
+ def later_prefix(dates)
63
+ I18n.t("edtf.terms.set_later_prefix_#{mode(dates)}",
64
+ default: later_prefix_default(dates))
65
+ end
66
+
67
+ def later_prefix_default(dates)
68
+ mode(dates) == 'inclusive' ? 'on and after ' : 'on or after '
69
+ end
70
+
71
+ def mode(date)
72
+ date.choice? ? 'exclusive' : 'inclusive'
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end