edtf-humanize 0.0.7 → 1.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 (49) hide show
  1. checksums.yaml +5 -5
  2. data/lib/edtf/humanize.rb +5 -1
  3. data/lib/edtf/humanize/formats.rb +2 -2
  4. data/lib/edtf/humanize/season.rb +13 -1
  5. data/lib/edtf/humanize/set.rb +20 -1
  6. data/lib/edtf/humanize/version.rb +1 -1
  7. data/spec/edtf_humanize_spec.rb +65 -0
  8. data/spec/spec_helper.rb +101 -0
  9. metadata +37 -96
  10. data/Rakefile +0 -34
  11. data/lib/tasks/edtf_humanize_tasks.rake +0 -4
  12. data/test/dummy/README.rdoc +0 -28
  13. data/test/dummy/Rakefile +0 -6
  14. data/test/dummy/app/assets/javascripts/application.js +0 -13
  15. data/test/dummy/app/assets/stylesheets/application.css +0 -15
  16. data/test/dummy/app/controllers/application_controller.rb +0 -5
  17. data/test/dummy/app/helpers/application_helper.rb +0 -2
  18. data/test/dummy/app/views/layouts/application.html.erb +0 -14
  19. data/test/dummy/bin/bundle +0 -3
  20. data/test/dummy/bin/rails +0 -4
  21. data/test/dummy/bin/rake +0 -4
  22. data/test/dummy/bin/setup +0 -29
  23. data/test/dummy/config.ru +0 -4
  24. data/test/dummy/config/application.rb +0 -32
  25. data/test/dummy/config/boot.rb +0 -5
  26. data/test/dummy/config/database.yml +0 -25
  27. data/test/dummy/config/environment.rb +0 -5
  28. data/test/dummy/config/environments/development.rb +0 -41
  29. data/test/dummy/config/environments/production.rb +0 -79
  30. data/test/dummy/config/environments/test.rb +0 -42
  31. data/test/dummy/config/initializers/assets.rb +0 -11
  32. data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
  33. data/test/dummy/config/initializers/cookies_serializer.rb +0 -3
  34. data/test/dummy/config/initializers/filter_parameter_logging.rb +0 -4
  35. data/test/dummy/config/initializers/inflections.rb +0 -16
  36. data/test/dummy/config/initializers/mime_types.rb +0 -4
  37. data/test/dummy/config/initializers/session_store.rb +0 -3
  38. data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
  39. data/test/dummy/config/locales/en.yml +0 -23
  40. data/test/dummy/config/routes.rb +0 -56
  41. data/test/dummy/config/secrets.yml +0 -22
  42. data/test/dummy/db/test.sqlite3 +0 -0
  43. data/test/dummy/log/test.log +0 -1140
  44. data/test/dummy/public/404.html +0 -67
  45. data/test/dummy/public/422.html +0 -67
  46. data/test/dummy/public/500.html +0 -66
  47. data/test/dummy/public/favicon.ico +0 -0
  48. data/test/edtf_humanize_test.rb +0 -78
  49. data/test/test_helper.rb +0 -19
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: dc28b955897a0df8fd98e869bfe4cbafc60c850b
4
- data.tar.gz: 67ceb2bfccf3438ec328f4dfc491bf7e3005e800
2
+ SHA256:
3
+ metadata.gz: 370eca8ed68c9afdd06117f0e584f82f2f48eac108a1113b77ce91355844bcba
4
+ data.tar.gz: 608b950683ce5117a1bcb9fe63380fc99ce705b53184f8e68c6e6a545527bbf7
5
5
  SHA512:
6
- metadata.gz: 7e7a12162e59e2defc0726c7cf4fef39d99a14759bdc5333e18b3981df9a944eca2a950066880f8cc8ce9eb625d131f54517c95fa221b215110467f73596607d
7
- data.tar.gz: e915de6f949f2de23aef3d4970e012751eaa5d7a3b240263876ad89bb1e7823ba96ffce2fa3217ee875622d348061c25174dc121b92f2a20ab90dab18b87fec7
6
+ metadata.gz: 4093df048a06504a30c04a8960ed6e253bb39a3d5d0015ac6f791287515ea9d2c800c0d04bf1e2834b5da2757243b47a1ab78589c5b259e7b9a7bd58ad4d2991
7
+ data.tar.gz: 6946c6594d3149788cbfc4ec50f770d450b3716817d7c8ad4c73c0ad58cd3a3b535436b1e373ccf998528d9ebdd4eb9faed24f42898da2d5de58b9ca9023bd7e
@@ -44,10 +44,12 @@ module Edtf
44
44
  :century_suffix,
45
45
  :unspecified_digit_substitute,
46
46
  :interval_connector,
47
+ :interval_unspecified_suffix,
47
48
  :set_dates_connector,
48
49
  :set_last_date_connector,
49
50
  :set_two_dates_connector,
50
- :interval_unspecified_suffix,
51
+ :set_earlier_prefix,
52
+ :set_later_prefix,
51
53
  :unknown
52
54
 
53
55
  def initialize
@@ -70,6 +72,8 @@ module Edtf
70
72
  @set_dates_connector = ", "
71
73
  @set_last_date_connector = " or "
72
74
  @set_two_dates_connector = " or "
75
+ @set_earlier_prefix = "on or before "
76
+ @set_later_prefix = "on or after "
73
77
 
74
78
  @unknown = "unknown"
75
79
  end
@@ -25,12 +25,12 @@ module Edtf
25
25
 
26
26
  # October 5, 1995
27
27
  def day_precision_format date
28
- date.strftime(Edtf::Humanize.configuration.day_precision_strftime_format)
28
+ I18n.localize(date, format: Edtf::Humanize.configuration.day_precision_strftime_format)
29
29
  end
30
30
 
31
31
  # October 1995
32
32
  def month_precision_format date
33
- date.strftime(Edtf::Humanize.configuration.month_precision_strftime_format)
33
+ I18n.localize(date, format: Edtf::Humanize.configuration.month_precision_strftime_format)
34
34
  end
35
35
 
36
36
  # 1995
@@ -5,7 +5,19 @@ module Edtf
5
5
  include Edtf::Humanize::Formats
6
6
 
7
7
  def humanize
8
- "#{apply_if_approximate(self)}#{self.season} #{self.year}#{apply_if_uncertain(self)}"
8
+ "#{apply_if_approximate(self)}"\
9
+ "#{translate_season(self.season)} #{self.year}"\
10
+ "#{apply_if_uncertain(self)}"
11
+ end
12
+
13
+ private
14
+
15
+ def translate_season(season)
16
+ begin
17
+ I18n.translate!("date.seasons.#{self.season}")
18
+ rescue I18n::MissingTranslationData
19
+ self.season
20
+ end
9
21
  end
10
22
 
11
23
  end
@@ -15,7 +15,26 @@ module Edtf
15
15
  private
16
16
 
17
17
  def format_set_entries(dates)
18
- dates.entries.map { |date| "#{apply_if_approximate(date)}#{simple_date_format(date)}" }
18
+ dates.entries.map.with_index { |date, index|
19
+ "#{apply_if_earlier(dates, index)}"\
20
+ "#{apply_if_later(dates, index)}"\
21
+ "#{apply_if_approximate(date)}"\
22
+ "#{simple_date_format(date)}"
23
+ }
24
+ end
25
+
26
+ # '[..1760-12-03]' => on or before December 3, 1760
27
+ def apply_if_earlier(dates, index)
28
+ if dates.earlier? && index == 0
29
+ Edtf::Humanize.configuration.set_earlier_prefix
30
+ end
31
+ end
32
+
33
+ # '[1760-12..]' => on or after December 1760
34
+ def apply_if_later(dates, index)
35
+ if dates.later? && (index + 1) == dates.size
36
+ Edtf::Humanize.configuration.set_later_prefix
37
+ end
19
38
  end
20
39
 
21
40
  end
@@ -1,5 +1,5 @@
1
1
  module Edtf
2
2
  module Humanize
3
- VERSION = "0.0.7"
3
+ VERSION = "1.0.0"
4
4
  end
5
5
  end
@@ -0,0 +1,65 @@
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
@@ -0,0 +1,101 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
16
+ #
17
+ RSpec.configure do |config|
18
+ # rspec-expectations config goes here. You can use an alternate
19
+ # assertion/expectation library such as wrong or the stdlib/minitest
20
+ # assertions if you prefer.
21
+ config.expect_with :rspec do |expectations|
22
+ # This option will default to `true` in RSpec 4. It makes the `description`
23
+ # and `failure_message` of custom matchers include text for helper methods
24
+ # defined using `chain`, e.g.:
25
+ # be_bigger_than(2).and_smaller_than(4).description
26
+ # # => "be bigger than 2 and smaller than 4"
27
+ # ...rather than:
28
+ # # => "be bigger than 2"
29
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
30
+ end
31
+
32
+ # rspec-mocks config goes here. You can use an alternate test double
33
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
34
+ config.mock_with :rspec do |mocks|
35
+ # Prevents you from mocking or stubbing a method that does not exist on
36
+ # a real object. This is generally recommended, and will default to
37
+ # `true` in RSpec 4.
38
+ mocks.verify_partial_doubles = true
39
+ end
40
+
41
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
42
+ # have no way to turn it off -- the option exists only for backwards
43
+ # compatibility in RSpec 3). It causes shared context metadata to be
44
+ # inherited by the metadata hash of host groups and examples, rather than
45
+ # triggering implicit auto-inclusion in groups with matching metadata.
46
+ config.shared_context_metadata_behavior = :apply_to_host_groups
47
+
48
+ # The settings below are suggested to provide a good initial experience
49
+ # with RSpec, but feel free to customize to your heart's content.
50
+ =begin
51
+ # This allows you to limit a spec run to individual examples or groups
52
+ # you care about by tagging them with `:focus` metadata. When nothing
53
+ # is tagged with `:focus`, all examples get run. RSpec also provides
54
+ # aliases for `it`, `describe`, and `context` that include `:focus`
55
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
56
+ config.filter_run_when_matching :focus
57
+
58
+ # Allows RSpec to persist some state between runs in order to support
59
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
60
+ # you configure your source control system to ignore this file.
61
+ config.example_status_persistence_file_path = "spec/examples.txt"
62
+
63
+ # Limits the available syntax to the non-monkey patched syntax that is
64
+ # recommended. For more details, see:
65
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
66
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
67
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
68
+ config.disable_monkey_patching!
69
+
70
+ # This setting enables warnings. It's recommended, but in some cases may
71
+ # be too noisy due to issues in dependencies.
72
+ config.warnings = true
73
+
74
+ # Many RSpec users commonly either run the entire suite or an individual
75
+ # file, and it's useful to allow more verbose output when running an
76
+ # individual spec file.
77
+ if config.files_to_run.one?
78
+ # Use the documentation formatter for detailed output,
79
+ # unless a formatter has already been configured
80
+ # (e.g. via a command-line flag).
81
+ config.default_formatter = "doc"
82
+ end
83
+
84
+ # Print the 10 slowest examples and example groups at the
85
+ # end of the spec run, to help surface which specs are running
86
+ # particularly slow.
87
+ config.profile_examples = 10
88
+
89
+ # Run specs in random order to surface order dependencies. If you find an
90
+ # order dependency and want to debug it, you can fix the order by providing
91
+ # the seed, which is printed after each run.
92
+ # --seed 1234
93
+ config.order = :random
94
+
95
+ # Seed global randomization in this process using the `--seed` CLI option.
96
+ # Setting this allows you to use `--seed` to deterministically reproduce
97
+ # test failures related to randomization by passing the same `--seed` value
98
+ # as the one that triggered the failure.
99
+ Kernel.srand config.seed
100
+ =end
101
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: edtf-humanize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cory Lown
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-28 00:00:00.000000000 Z
11
+ date: 2020-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: edtf
@@ -37,9 +37,6 @@ dependencies:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
39
  version: '4'
40
- - - "<"
41
- - !ruby/object:Gem::Version
42
- version: '6'
43
40
  type: :runtime
44
41
  prerelease: false
45
42
  version_requirements: !ruby/object:Gem::Requirement
@@ -47,29 +44,48 @@ dependencies:
47
44
  - - ">="
48
45
  - !ruby/object:Gem::Version
49
46
  version: '4'
50
- - - "<"
51
- - !ruby/object:Gem::Version
52
- version: '6'
53
47
  - !ruby/object:Gem::Dependency
54
- name: rails
48
+ name: rake
55
49
  requirement: !ruby/object:Gem::Requirement
56
50
  requirements:
57
- - - ">="
51
+ - - "~>"
58
52
  - !ruby/object:Gem::Version
59
- version: '4'
60
- - - "<"
53
+ version: '13.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '13.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
61
66
  - !ruby/object:Gem::Version
62
- version: '6'
67
+ version: '3.9'
63
68
  type: :development
64
69
  prerelease: false
65
70
  version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '3.9'
75
+ - !ruby/object:Gem::Dependency
76
+ name: bump
77
+ requirement: !ruby/object:Gem::Requirement
66
78
  requirements:
67
79
  - - ">="
68
80
  - !ruby/object:Gem::Version
69
- version: '4'
70
- - - "<"
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
71
87
  - !ruby/object:Gem::Version
72
- version: '6'
88
+ version: '0'
73
89
  description: This gem adds a humanize method to EDTF::Decade, EDTF::Interval, EDTF::Set,
74
90
  EDTF::Season, EDTF::Unknown, and Date (ISO 8601 compliant) objects.
75
91
  email:
@@ -79,7 +95,6 @@ extensions: []
79
95
  extra_rdoc_files: []
80
96
  files:
81
97
  - LICENSE.txt
82
- - Rakefile
83
98
  - lib/edtf-humanize.rb
84
99
  - lib/edtf/humanize.rb
85
100
  - lib/edtf/humanize/century.rb
@@ -91,45 +106,8 @@ files:
91
106
  - lib/edtf/humanize/set.rb
92
107
  - lib/edtf/humanize/unknown.rb
93
108
  - lib/edtf/humanize/version.rb
94
- - lib/tasks/edtf_humanize_tasks.rake
95
- - test/dummy/README.rdoc
96
- - test/dummy/Rakefile
97
- - test/dummy/app/assets/javascripts/application.js
98
- - test/dummy/app/assets/stylesheets/application.css
99
- - test/dummy/app/controllers/application_controller.rb
100
- - test/dummy/app/helpers/application_helper.rb
101
- - test/dummy/app/views/layouts/application.html.erb
102
- - test/dummy/bin/bundle
103
- - test/dummy/bin/rails
104
- - test/dummy/bin/rake
105
- - test/dummy/bin/setup
106
- - test/dummy/config.ru
107
- - test/dummy/config/application.rb
108
- - test/dummy/config/boot.rb
109
- - test/dummy/config/database.yml
110
- - test/dummy/config/environment.rb
111
- - test/dummy/config/environments/development.rb
112
- - test/dummy/config/environments/production.rb
113
- - test/dummy/config/environments/test.rb
114
- - test/dummy/config/initializers/assets.rb
115
- - test/dummy/config/initializers/backtrace_silencers.rb
116
- - test/dummy/config/initializers/cookies_serializer.rb
117
- - test/dummy/config/initializers/filter_parameter_logging.rb
118
- - test/dummy/config/initializers/inflections.rb
119
- - test/dummy/config/initializers/mime_types.rb
120
- - test/dummy/config/initializers/session_store.rb
121
- - test/dummy/config/initializers/wrap_parameters.rb
122
- - test/dummy/config/locales/en.yml
123
- - test/dummy/config/routes.rb
124
- - test/dummy/config/secrets.yml
125
- - test/dummy/db/test.sqlite3
126
- - test/dummy/log/test.log
127
- - test/dummy/public/404.html
128
- - test/dummy/public/422.html
129
- - test/dummy/public/500.html
130
- - test/dummy/public/favicon.ico
131
- - test/edtf_humanize_test.rb
132
- - test/test_helper.rb
109
+ - spec/edtf_humanize_spec.rb
110
+ - spec/spec_helper.rb
133
111
  homepage: https://github.com/duke-libraries/edtf-humanize
134
112
  licenses:
135
113
  - BSD-3-Clause
@@ -149,47 +127,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
127
  - !ruby/object:Gem::Version
150
128
  version: '0'
151
129
  requirements: []
152
- rubyforge_project:
153
- rubygems_version: 2.5.1
130
+ rubygems_version: 3.0.6
154
131
  signing_key:
155
132
  specification_version: 4
156
133
  summary: This gem adds a humanize method to EDTF dates.
157
134
  test_files:
158
- - test/dummy/app/assets/javascripts/application.js
159
- - test/dummy/app/assets/stylesheets/application.css
160
- - test/dummy/app/controllers/application_controller.rb
161
- - test/dummy/app/helpers/application_helper.rb
162
- - test/dummy/app/views/layouts/application.html.erb
163
- - test/dummy/bin/bundle
164
- - test/dummy/bin/rails
165
- - test/dummy/bin/rake
166
- - test/dummy/bin/setup
167
- - test/dummy/config/application.rb
168
- - test/dummy/config/boot.rb
169
- - test/dummy/config/database.yml
170
- - test/dummy/config/environment.rb
171
- - test/dummy/config/environments/development.rb
172
- - test/dummy/config/environments/production.rb
173
- - test/dummy/config/environments/test.rb
174
- - test/dummy/config/initializers/assets.rb
175
- - test/dummy/config/initializers/backtrace_silencers.rb
176
- - test/dummy/config/initializers/cookies_serializer.rb
177
- - test/dummy/config/initializers/filter_parameter_logging.rb
178
- - test/dummy/config/initializers/inflections.rb
179
- - test/dummy/config/initializers/mime_types.rb
180
- - test/dummy/config/initializers/session_store.rb
181
- - test/dummy/config/initializers/wrap_parameters.rb
182
- - test/dummy/config/locales/en.yml
183
- - test/dummy/config/routes.rb
184
- - test/dummy/config/secrets.yml
185
- - test/dummy/config.ru
186
- - test/dummy/db/test.sqlite3
187
- - test/dummy/log/test.log
188
- - test/dummy/public/404.html
189
- - test/dummy/public/422.html
190
- - test/dummy/public/500.html
191
- - test/dummy/public/favicon.ico
192
- - test/dummy/Rakefile
193
- - test/dummy/README.rdoc
194
- - test/edtf_humanize_test.rb
195
- - test/test_helper.rb
135
+ - spec/spec_helper.rb
136
+ - spec/edtf_humanize_spec.rb