An open API service indexing awesome lists of open source software.

https://github.com/corylown/edtf-humanize

This gem adds a humanize method to EDTF dates.
https://github.com/corylown/edtf-humanize

code4lib edtf edtf-ruby

Last synced: 2 days ago
JSON representation

This gem adds a humanize method to EDTF dates.

Awesome Lists containing this project

README

          

# edtf-humanize

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.

See the [edtf-ruby project's documentation](https://github.com/inukshuk/edtf-ruby) for details about supported EDTF string formats and other implementation details.

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.

## Installation

In a Rails application using Bundler

Add the following to your Gemfile:

```
gem 'edtf-humanize'
```

Then run:

```
> bundle install
```

To use in other contexts install the gem and require it:

```
> gem install edtf-humanize
```

```
require 'edtf-humanize'
```

## Examples

### Date (ISO 8601)

```
> d = Date.edtf('1975-07-01')
=> Tue, 01 Jul 1975
> d.humanize
=> "July 1, 1975"
> d = Date.edtf('1981~')
=> Thu, 01 Jan 1981
> d.humanize
=> "circa 1981"
> d = Date.edtf('198u')
=> Tue, 01 Jan 1980
> d.humanize
=> "198x"
```

### EDTF::Season

```
> d = Date.edtf('1975-22')
=> #
> d.humanize
=> "summer 1975"
```

### EDTF::Decade

```
> d = Date.edtf('197x')
=> #
> d.humanize
=> "1970s"
```

### EDTF::Century

```
> d = Date.edtf('19xx')
=> #
> d.humanize
=> "1900s"
```

### EDTF::Interval

```
> d = Date.edtf('1981/1985')
=> #
> d.humanize
=> "1981 to 1985"
```

### EDTF::Set

```
> d = Date.edtf('[1888, 1889, 1891]')
=> #, @choice=true, @later=false, @earlier=false>
> d.humanize
=> "1888, 1889 or 1891"
```

### EDTF::Unknown

```
> d = Date.edtf('uuuu')
=> #
> d.humanize
=> "unknown"
```

## Internationalization

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.

Examples with current locale `:fr`:

```
> Date.edtf('1975-24').humanize
=> "hiver 1975"
> Date.edtf('20xx').humanize
=> "XXIe siècle"
```

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.:

```
edtf-humanize/lib/edtf/humanize.rb
edtf-humanize/config/locales/fr.edtf.yml
edtf-humanize/lib/edtf/humanize/language/french.rb
edtf-humanize/spec/edtf/humanize_fr_spec.rb
```

## Contributions

Contributions, especially to add support for additional languages are welcome. Tests are expected and written using RSpec. Code style is enforced with Rubocop.