edtf-humanize 0.0.4 → 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.
Files changed (70) hide show
  1. checksums.yaml +5 -5
  2. data/config/locales/en.edtf.yml +44 -0
  3. data/config/locales/fr.edtf.yml +55 -0
  4. data/lib/edtf-humanize.rb +5 -0
  5. data/lib/edtf/humanize.rb +22 -41
  6. data/lib/edtf/humanize/century.rb +4 -4
  7. data/lib/edtf/humanize/decade.rb +4 -4
  8. data/lib/edtf/humanize/interval.rb +4 -17
  9. data/lib/edtf/humanize/iso_date.rb +4 -4
  10. data/lib/edtf/humanize/language.rb +13 -0
  11. data/lib/edtf/humanize/language/default.rb +17 -0
  12. data/lib/edtf/humanize/language/default/century.rb +20 -0
  13. data/lib/edtf/humanize/language/default/decade.rb +21 -0
  14. data/lib/edtf/humanize/language/default/formats.rb +115 -0
  15. data/lib/edtf/humanize/language/default/interval.rb +132 -0
  16. data/lib/edtf/humanize/language/default/iso_date.rb +21 -0
  17. data/lib/edtf/humanize/language/default/season.rb +30 -0
  18. data/lib/edtf/humanize/language/default/set.rb +78 -0
  19. data/lib/edtf/humanize/language/default/unknown.rb +17 -0
  20. data/lib/edtf/humanize/language/english.rb +11 -0
  21. data/lib/edtf/humanize/language/french.rb +36 -0
  22. data/lib/edtf/humanize/season.rb +4 -4
  23. data/lib/edtf/humanize/set.rb +4 -12
  24. data/lib/edtf/humanize/unknown.rb +5 -3
  25. data/lib/edtf/humanize/version.rb +3 -1
  26. data/spec/edtf_humanize_en_spec.rb +102 -0
  27. data/spec/edtf_humanize_fr_spec.rb +110 -0
  28. data/spec/spec_helper.rb +103 -0
  29. metadata +102 -100
  30. data/Rakefile +0 -34
  31. data/lib/edtf/humanize/formats.rb +0 -73
  32. data/lib/tasks/edtf_humanize_tasks.rake +0 -4
  33. data/test/dummy/README.rdoc +0 -28
  34. data/test/dummy/Rakefile +0 -6
  35. data/test/dummy/app/assets/javascripts/application.js +0 -13
  36. data/test/dummy/app/assets/stylesheets/application.css +0 -15
  37. data/test/dummy/app/controllers/application_controller.rb +0 -5
  38. data/test/dummy/app/helpers/application_helper.rb +0 -2
  39. data/test/dummy/app/views/layouts/application.html.erb +0 -14
  40. data/test/dummy/bin/bundle +0 -3
  41. data/test/dummy/bin/rails +0 -4
  42. data/test/dummy/bin/rake +0 -4
  43. data/test/dummy/bin/setup +0 -29
  44. data/test/dummy/config.ru +0 -4
  45. data/test/dummy/config/application.rb +0 -26
  46. data/test/dummy/config/boot.rb +0 -5
  47. data/test/dummy/config/database.yml +0 -25
  48. data/test/dummy/config/environment.rb +0 -5
  49. data/test/dummy/config/environments/development.rb +0 -41
  50. data/test/dummy/config/environments/production.rb +0 -79
  51. data/test/dummy/config/environments/test.rb +0 -42
  52. data/test/dummy/config/initializers/assets.rb +0 -11
  53. data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
  54. data/test/dummy/config/initializers/cookies_serializer.rb +0 -3
  55. data/test/dummy/config/initializers/filter_parameter_logging.rb +0 -4
  56. data/test/dummy/config/initializers/inflections.rb +0 -16
  57. data/test/dummy/config/initializers/mime_types.rb +0 -4
  58. data/test/dummy/config/initializers/session_store.rb +0 -3
  59. data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
  60. data/test/dummy/config/locales/en.yml +0 -23
  61. data/test/dummy/config/routes.rb +0 -56
  62. data/test/dummy/config/secrets.yml +0 -22
  63. data/test/dummy/db/test.sqlite3 +0 -0
  64. data/test/dummy/log/test.log +0 -865
  65. data/test/dummy/public/404.html +0 -67
  66. data/test/dummy/public/422.html +0 -67
  67. data/test/dummy/public/500.html +0 -66
  68. data/test/dummy/public/favicon.ico +0 -0
  69. data/test/edtf_humanize_test.rb +0 -78
  70. data/test/test_helper.rb +0 -19
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: f598275a9531dce2588e12032e88134a6beb0395
4
- data.tar.gz: 8123239d6628e382e3d55dc7ccc1647a3422216a
2
+ SHA256:
3
+ metadata.gz: dcd453eb435bc411afc324c1fe00324311b91ad5feb2559cf44f6e7df30dc610
4
+ data.tar.gz: '019a07057a906c4d45fe710c7034bab92a63fb86241ffca22858049c51bb4085'
5
5
  SHA512:
6
- metadata.gz: 42710d68370529b5a90241e63392b0ad07e83d124d35d83d6d73d816deded6a817578ec6c5fa2dd07be69a88f03dbda77ecae648162af9887306815ed40379e7
7
- data.tar.gz: 1885e8645447d2a3bb44668cc22be7095c3909640ccc77e4e042021b657891fc33de9c0adff9952dfeae2564a36787fc48064193b29c40796e2a8d4e129a5455
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"
@@ -1 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'edtf/humanize'
4
+
5
+ I18n.load_path +=
6
+ Dir.glob(File.dirname(__FILE__) + '/../config/locales/*.{rb,yml}')
@@ -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/formats'
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,47 +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
- :set_dates_connector,
48
- :set_last_date_connector,
49
- :set_two_dates_connector,
50
- :interval_unspecified_suffix,
51
- :unknown
52
-
53
48
  def initialize
54
- @day_precision_strftime_format = "%B %-d, %Y"
55
- @month_precision_strftime_format = "%B %Y"
56
- @year_precision_strftime_format = "%Y"
57
-
58
- @approximate_date_prefix = "circa "
59
-
60
- @uncertain_date_suffix = "?"
61
-
62
- @decade_suffix = "s"
63
- @century_suffix = "s"
64
-
65
- @unspecified_digit_substitute = "x"
66
-
67
- @interval_connector = " to "
68
- @interval_unspecified_suffix = "s"
69
-
70
- @set_dates_connector = ", "
71
- @set_last_date_connector = " or "
72
- @set_two_dates_connector = " or "
73
-
74
- @unknown = "unknown"
49
+ @language_strategies = {
50
+ default: Edtf::Humanize::Language::Default,
51
+ en: Edtf::Humanize::Language::English,
52
+ fr: Edtf::Humanize::Language::French
53
+ }
75
54
  end
76
55
 
56
+ def language_strategy(language)
57
+ @language_strategies[language.to_sym] || @language_strategies[:default]
58
+ end
77
59
  end
78
-
79
60
  end
80
61
  end
@@ -1,13 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Edtf
2
4
  module Humanize
3
5
  module Century
6
+ include Edtf::Humanize::Language
4
7
 
5
- include Edtf::Humanize::Formats
6
-
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
6
+ include Edtf::Humanize::Language
4
7
 
5
- include Edtf::Humanize::Formats
6
-
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,26 +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)}#{simple_date_format(self.from)}#{Edtf::Humanize.configuration.interval_connector}#{simple_date_format(self.to)}"
9
- end
10
-
11
- private
12
-
13
- # '198u/199u' => 1980s to 1990s
14
- def apply_if_unspecified_year date
15
- display = date_precision(date)
16
- if date.respond_to? :unspecified?
17
- if date.unspecified? :year
18
- display << Edtf::Humanize.configuration.interval_unspecified_suffix
19
- end
20
- end
21
- display
9
+ language_strategy::Interval.humanizer(self)
22
10
  end
23
-
24
11
  end
25
12
  end
26
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,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Edtf
4
+ module Humanize
5
+ module Language
6
+ extend self
7
+
8
+ def language_strategy
9
+ Edtf::Humanize.configuration.language_strategy(I18n.locale)
10
+ end
11
+ end
12
+ end
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