dotiw 3.1.1 → 5.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ruby.yml +45 -0
  3. data/.gitignore +2 -1
  4. data/.rspec +2 -0
  5. data/Appraisals +19 -0
  6. data/CHANGELOG.md +31 -6
  7. data/Gemfile +2 -0
  8. data/MIT-LICENSE +1 -1
  9. data/README.markdown +147 -62
  10. data/Rakefile +3 -1
  11. data/dotiw.gemspec +17 -17
  12. data/gemfiles/.bundle/config +2 -0
  13. data/gemfiles/rails_4.gemfile +9 -0
  14. data/gemfiles/rails_5.0.gemfile +9 -0
  15. data/gemfiles/rails_5.1.gemfile +9 -0
  16. data/gemfiles/rails_5.2.gemfile +9 -0
  17. data/gemfiles/rails_6.0.gemfile +9 -0
  18. data/lib/dotiw.rb +32 -13
  19. data/lib/dotiw/action_view/helpers/date_helper.rb +25 -0
  20. data/lib/dotiw/locale/ar.yml +104 -0
  21. data/lib/dotiw/locale/da.yml +35 -0
  22. data/lib/dotiw/locale/de.yml +36 -1
  23. data/lib/dotiw/locale/en.yml +35 -0
  24. data/lib/dotiw/locale/es.yml +36 -1
  25. data/lib/dotiw/locale/fr.yml +35 -0
  26. data/lib/dotiw/locale/id.yml +35 -0
  27. data/lib/dotiw/locale/it.yml +35 -0
  28. data/lib/dotiw/locale/ja.yml +35 -0
  29. data/lib/dotiw/locale/ko.yml +48 -0
  30. data/lib/dotiw/locale/nb.yml +36 -1
  31. data/lib/dotiw/locale/nl.yml +35 -0
  32. data/lib/dotiw/locale/pl.yml +42 -0
  33. data/lib/dotiw/locale/pt-BR.yml +35 -0
  34. data/lib/dotiw/locale/ru.yml +37 -0
  35. data/lib/dotiw/locale/sv.yml +48 -0
  36. data/lib/dotiw/locale/vi.yml +48 -0
  37. data/lib/dotiw/locale/zh-CN.yml +48 -0
  38. data/lib/dotiw/locale/zh-TW.yml +60 -0
  39. data/lib/dotiw/methods.rb +99 -0
  40. data/lib/dotiw/time_hash.rb +39 -33
  41. data/lib/dotiw/version.rb +2 -2
  42. data/spec/lib/dotiw_spec.rb +256 -157
  43. data/spec/lib/i18n/ar.yml +2 -0
  44. data/spec/lib/i18n/da.yml +2 -0
  45. data/spec/lib/i18n/de.yml +2 -0
  46. data/spec/lib/i18n/en.yml +2 -0
  47. data/spec/lib/i18n/es.yml +3 -0
  48. data/spec/lib/i18n/fr.yml +2 -0
  49. data/spec/lib/i18n/id.yml +2 -0
  50. data/spec/lib/i18n/it.yml +3 -0
  51. data/spec/lib/i18n/ja.yml +2 -0
  52. data/spec/lib/i18n/ko.yml +2 -0
  53. data/spec/lib/i18n/nb.yml +2 -0
  54. data/spec/lib/i18n/nl.yml +2 -0
  55. data/spec/lib/i18n/pl.yml +2 -0
  56. data/spec/lib/i18n/pt-BR.yml +2 -0
  57. data/spec/lib/i18n/ru.yml +5 -0
  58. data/spec/lib/i18n/sv.yml +2 -0
  59. data/spec/lib/i18n/vi.yml +22 -0
  60. data/spec/lib/i18n/zh-CN.yml +2 -0
  61. data/spec/lib/i18n/zh-TW.yml +2 -0
  62. data/spec/spec_helper.rb +2 -9
  63. metadata +98 -18
  64. data/.travis.yml +0 -11
  65. data/lib/dotiw/action_view_ext/helpers/date_helper.rb +0 -103
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 0b71e3935ad86d61036e453b41579881ac1a8f3b
4
- data.tar.gz: 26e1ce49677a8dead460ac3c3b0b4db93f3e196b
2
+ SHA256:
3
+ metadata.gz: 2d52199ee419e6e9effc50ae35409aa01605c4e2b05306ddf2ba4a7d5d9a627d
4
+ data.tar.gz: c069bf8d7cc9078b9091284084907f777155b2a698b9fe9067ad4ee621dd4982
5
5
  SHA512:
6
- metadata.gz: d6157f043c6114509982a82b1bc5c6973b81bbcb7cb4293a8388dd1736cac3427c578301f866d86f685a201fdc7e1163067c9ef4e32d2a738804578290a4c6b8
7
- data.tar.gz: 837d5ec5c403dcb288bba9b3be908b98ad9d6e7191b3f777014f5b77242c84ff5d48fb43ce25c4614bcd2ff6659b34d2e8b74f4400e7e213c41dc8fe9a8ccdb8
6
+ metadata.gz: 9578117b3360f17e92d49ffe07b4071f805d9c8737033c5431f9ed6e6a9e75aec787d3ef22c9e156af2f1186083cb38c9b4039b9cb12b05cf4ea0dbfd7ce0d83
7
+ data.tar.gz: c463d39fdf6b1e811a850b23ab363f4a1e4bf3cd76515621d90ee347489762e4cb0c436cdca038487954af6124c60ef9b84902ccc5a9a7ffa034aabee0826b16
@@ -0,0 +1,45 @@
1
+ name: Ruby
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ pull_request:
8
+ branches:
9
+ - master
10
+
11
+ jobs:
12
+ build:
13
+ runs-on: ubuntu-latest
14
+ strategy:
15
+ fail-fast: false
16
+ matrix:
17
+ include:
18
+ - ruby-version: 2.5.x
19
+ - ruby-version: 2.6.x
20
+ - ruby-version: 2.4.x
21
+ bundler-version: 1.17.3
22
+ gemfile: gemfiles/rails_4.gemfile
23
+ - ruby-version: 2.6.x
24
+ gemfile: gemfiles/rails_5.0.gemfile
25
+ - ruby-version: 2.6.x
26
+ gemfile: gemfiles/rails_5.1.gemfile
27
+ - ruby-version: 2.6.x
28
+ gemfile: gemfiles/rails_5.2.gemfile
29
+ - ruby-version: 2.6.x
30
+ gemfile: gemfiles/rails_6.0.gemfile
31
+ steps:
32
+ - uses: actions/checkout@v2
33
+ - name: Set up Ruby
34
+ uses: actions/setup-ruby@v1
35
+ with:
36
+ ruby-version: ${{ matrix.ruby-version }}
37
+ - name: Build and test
38
+ env:
39
+ BUNDLE_GEMFILE: ${{ matrix.gemfile }}
40
+ BUNDLER: ${{ matrix.bundler-version }}
41
+ run: |
42
+ gem uninstall bundler
43
+ gem install bundler -v ${BUNDLER:-2.1.4}
44
+ bundle install --jobs 4 --retry 3
45
+ bundle exec rake
data/.gitignore CHANGED
@@ -2,4 +2,5 @@ tmp
2
2
  pkg
3
3
  spec/fixtures/database.yml
4
4
  .rvmrc
5
- Gemfile.lock
5
+ Gemfile.lock
6
+ gemfiles/*.lock
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,19 @@
1
+ appraise 'rails_4' do
2
+ gem 'rails', '~> 4.0'
3
+ end
4
+
5
+ appraise 'rails_5.0' do
6
+ gem 'rails', '~> 5.0.0'
7
+ end
8
+
9
+ appraise 'rails_5.1' do
10
+ gem 'rails', '~> 5.1.0'
11
+ end
12
+
13
+ appraise 'rails_5.2' do
14
+ gem 'rails', '~> 5.2.0'
15
+ end
16
+
17
+ appraise 'rails_6.0' do
18
+ gem 'rails', '~> 6.0.0'
19
+ end
@@ -1,10 +1,35 @@
1
+ ## 5.2.0 (2020/10/03)
2
+
3
+ * [#94](https://github.com/radar/distance_of_time_in_words/pull/94): Add :compact formatting option - [@booty](https://github.com/booty).
4
+ * [#112](https://github.com/radar/distance_of_time_in_words/pull/112): Add Swedish language support - [@davidwessman](https://github.com/davidwessman).
5
+ * [#114](https://github.com/radar/distance_of_time_in_words/pull/114): Add Traditional Chinese (Taiwan) language support - [@sibevin](https://github.com/sibevin).
6
+
7
+ ## 5.1.0 (2020/08/05)
8
+
9
+ * [#111](https://github.com/radar/distance_of_time_in_words/pull/111): Fix: `NoMethodError` when calling `ActionController::Base.helpers.distance_of_time_in_words` - [@denisahearn](https://github.com/denisahearn).
10
+ * [#106](https://github.com/radar/distance_of_time_in_words/pull/106): Add Vietnamese language support - [@runlevel5 ](https://github.com/runlevel5).
11
+
12
+ ## 5.0.0 (2020/05/07)
13
+
14
+ * [#105](https://github.com/radar/distance_of_time_in_words/pull/105): Support for Ruby w/o Rails - [@dblock](https://github.com/dblock).
15
+ * [#108](https://github.com/radar/distance_of_time_in_words/pull/108): Fix negative weeks - [@ivanovaleksey](https://github.com/ivanovaleksey).
16
+
17
+ ## 4.0.1 (2018/06/01)
18
+
1
19
  ## 3.1.1 (2016/03/08)
2
- * Add CHANGELOG.md
3
20
 
4
21
  ## 3.1.0 (2016/03/07)
5
22
 
6
- * [#68](https://github.com/radar/dotiw/pull/68): Add support for weeks - [@lauranjansen](https://github.com/lauranjansen)
7
- * [#69](https://github.com/radar/dotiw/pull/69): Add Indonesian language support - [@avidmaulanas](https://github.com/avidmaulanas)
8
- * [#70](https://github.com/radar/dotiw/pull/70): Add French language support - [@geo1004](https://github.com/geo1004)
9
- * [#72](https://github.com/radar/dotiw/pull/72): Add Danish language support - [@kaspernj](https://github.com/kaspernj)
10
- * [#71](https://github.com/radar/dotiw/pull/71): Update bundler and ruby versions for Travis CI - [@lauranjansen](https://github.com/lauranjansen)
23
+ * [#68](https://github.com/radar/dotiw/pull/68): Add support for weeks - [@lauranjansen](https://github.com/lauranjansen).
24
+ * [#69](https://github.com/radar/dotiw/pull/69): Add Indonesian language support - [@avidmaulanas](https://github.com/avidmaulanas).
25
+ * [#70](https://github.com/radar/dotiw/pull/70): Add French language support - [@geo1004](https://github.com/geo1004).
26
+ * [#72](https://github.com/radar/dotiw/pull/72): Add Danish language support - [@kaspernj](https://github.com/kaspernj).
27
+ * [#71](https://github.com/radar/dotiw/pull/71): Update bundler and ruby versions for Travis CI - [@lauranjansen](https://github.com/lauranjansen).
28
+
29
+ ## 3.0.1 (2015/04/09)
30
+
31
+ ## 3.0 (2015/04/09)
32
+
33
+ ## 0.2.4 (2009/10/18)
34
+
35
+ * Initial public release - [@radar](https://github.com/radar).
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'http://rubygems.org'
2
4
 
3
5
  gemspec
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009 Ryan Bigg
1
+ Copyright (c) 2009-2020 Ryan Bigg
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -1,54 +1,83 @@
1
- # dotiw [![](https://travis-ci.org/radar/dotiw.png)](https://travis-ci.org/radar/dotiw)
1
+ # dotiw ![Ruby](https://github.com/radar/distance_of_time_in_words/workflows/Ruby/badge.svg)
2
2
 
3
- dotiw is a gem for Rails that overrides the default `distance_of_time_in_words` and provides a more accurate output. Do you crave accuracy down to the second? So do I. That's why I made this gem. Take this for a totally kickass example:
3
+ The `dotiw` library that adds `distance_of_time_in_words` to any Ruby project, or overrides the default implementation in Rails with more accurate output.
4
4
 
5
- >> distance_of_time_in_words(Time.now, Time.now + 1.year + 2.months + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds, true)
6
- => "1 year, 2 months, 3 weeks, 4 days, 5 hours, 6 minutes, and 7 seconds"
5
+ Do you crave accuracy down to the second? So do I. That's why I made this gem.
6
+
7
+ ## Install
8
+
9
+ Add to your `Gemfile`.
10
+
11
+ ```ruby
12
+ gem 'dotiw'
13
+ ```
14
+
15
+ Run `bundle install`.
16
+
17
+ ### Pure Ruby
18
+
19
+ ```ruby
20
+ require 'dotiw'
21
+
22
+ include DOTIW::Methods
23
+ ```
24
+
25
+ ### Rails
26
+
27
+ ```ruby
28
+ require 'dotiw'
29
+
30
+ include ActionView::Helpers::DateHelper
31
+ include ActionView::Helpers::TextHelper
32
+ include ActionView::Helpers::NumberHelper
33
+ ```
34
+
35
+ ## distance\_of\_time\_in\_words
36
+
37
+ Take this for a totally kick-ass example:
38
+
39
+ ```ruby
40
+ >> distance_of_time_in_words(Time.now, Time.now + 1.year + 2.months + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds, true)
41
+ => "1 year, 2 months, 3 weeks, 4 days, 5 hours, 6 minutes, and 7 seconds"
42
+ ```
7
43
 
8
44
  Also if one of the measurement is zero it will not output it:
9
45
 
10
- >> distance_of_time_in_words(Time.now, Time.now + 1.year + 2.months + 5.hours + 6.minutes + 7.seconds, true)
11
- => "1 year, 2 months, 4 days, 6 minutes, and 7 seconds"
46
+ ```ruby
47
+ >> distance_of_time_in_words(Time.now, Time.now + 1.year + 2.months + 5.hours + 6.minutes + 7.seconds, true)
48
+ => "1 year, 2 months, 4 days, 6 minutes, and 7 seconds"
49
+ ```
12
50
 
13
51
  Better than "about 1 year", am I right? Of course I am.
14
52
 
15
53
  "But Ryan!", you say, "What happens if the time is only in seconds but because of the default the seconds aren't shown? Won't it be blank?"
16
54
  "No!" I triumphantly reply:
17
55
 
18
- >> distance_of_time_in_words(Time.now, Time.now + 1.second, false)
19
- => "1 second"
56
+ ```ruby
57
+ >> distance_of_time_in_words(Time.now, Time.now + 1.second, false)
58
+ => "1 second"
59
+ ```
20
60
 
21
61
  The third argument for this method is whether or not to include seconds. By default this is `false` (because in Rails' `distance_of_time_in_words` it is), you can turn it on though by passing `true` as the third argument:
22
62
 
23
- >> distance_of_time_in_words(Time.now, Time.now + 1.year + 1.second, true)
24
- => "1 year, and 1 second"
63
+ ```ruby
64
+ >> distance_of_time_in_words(Time.now, Time.now + 1.year + 1.second, true)
65
+ => "1 year, and 1 second"
66
+ ```
25
67
 
26
- Yes this could just be merged into the options hash but I'm leaving it here to ensure "backwards-compatibility",
27
- because that's just an insanely radical thing to do. \m/
68
+ Yes this could just be merged into the options hash but I'm leaving it here to ensure "backwards-compatibility", because that's just an insanely radical thing to do. \m/
28
69
 
29
70
  The last argument is an optional options hash that can be used to manipulate behavior and (which uses `to_sentence`).
30
71
 
31
72
  Don't like having to pass in `Time.now` all the time? Then use `time_ago_in_words` which also will *rock your
32
73
  world*:
33
74
 
34
- >> time_ago_in_words(Time.now + 3.days + 1.second)
35
- => "3 days, and 1 second"
36
-
37
- Oh, and did I mention it supports I18n? Oh yeah. Rock on!
38
-
39
- ## Install
40
-
41
- Install it as a gem:
42
-
43
75
  ```ruby
44
- gem 'dotiw'
76
+ >> time_ago_in_words(Time.now + 3.days + 1.second)
77
+ => "3 days, and 1 second"
45
78
  ```
46
79
 
47
- Or from GitHub:
48
-
49
- ```ruby
50
- gem 'dotiw', github: 'radar/dotiw'
51
- ```
80
+ Oh, and did I mention it supports I18n? Oh yeah. Rock on!
52
81
 
53
82
  ### Options
54
83
 
@@ -56,10 +85,12 @@ gem 'dotiw', github: 'radar/dotiw'
56
85
 
57
86
  You can pass in a locale and it'll output it in whatever language you want (provided you have translations, otherwise it'll default to your app's default locale (the `config.i18n.default_locale` you have set in `/config/application.rb`):
58
87
 
59
- >> distance_of_time_in_words(Time.now, Time.now + 1.minute, false, :locale => :es)
60
- => "1 minuto"
88
+ ```ruby
89
+ >> distance_of_time_in_words(Time.now, Time.now + 1.minute, false, locale: :es)
90
+ => "1 minuto"
91
+ ```
61
92
 
62
- This will also be passed to `to_sentence`
93
+ This will also be passed to `to_sentence`.
63
94
 
64
95
  #### :vague
65
96
 
@@ -67,46 +98,60 @@ Specify this if you want it to use the old `distance_of_time_in_words`. The valu
67
98
 
68
99
  #### :accumulate_on
69
100
 
70
- Specifies the maximum output unit which will accumulate all the surplus. Say you set it to seconds and your time difference is of 2 minutes then the output would be 120 seconds. Here's a code example:
101
+ Specifies the maximum output unit which will accumulate all the surplus. Say you set it to seconds and your time difference is of 2 minutes then the output would be 120 seconds.
71
102
 
72
- >> distance_of_time_in_words(Time.now, Time.now + 2.hours + 70.seconds, true, :accumulate_on => :minutes)
73
- => "121 minutes and 10 seconds"
103
+ ```ruby
104
+ >> distance_of_time_in_words(Time.now, Time.now + 2.hours + 70.seconds, true, accumulate_on: :minutes)
105
+ => "121 minutes and 10 seconds"
106
+ ```
74
107
 
75
108
  #### :only
76
109
 
77
110
  Only want a specific measurement of time? No problem!
78
111
 
79
- >> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.minute, false, :only => :minutes)
80
- => "1 minute"
112
+ ```ruby
113
+ >> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.minute, false, only: :minutes)
114
+ => "1 minute"
115
+ ```
81
116
 
82
117
  You only want some? No problem too!
83
118
 
84
- >> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.day + 1.minute, false, :only => [:minutes, :hours])
85
- => "1 hour and 1 minute"
119
+ ```ruby
120
+ >> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.day + 1.minute, false, only: [:minutes, :hours])
121
+ => "1 hour and 1 minute"
122
+ ```
86
123
 
87
124
  #### :except
88
125
 
89
126
  Don't want a measurement of time? No problem!
90
127
 
91
- >> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.minute, false, :except => :minutes)
92
- => "1 hour"
128
+ ```ruby
129
+ >> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.minute, false, except: :minutes)
130
+ => "1 hour"
131
+ ```
93
132
 
94
133
  Culling a whole group of measurements of time:
95
134
 
96
- >> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.day + 1.minute, false, :except => [:minutes, :hours])
97
- => "1 day"
135
+ ```ruby
136
+ >> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.day + 1.minute, false, except: [:minutes, :hours])
137
+ => "1 day"
138
+ ```
98
139
 
99
140
  #### :highest\_measure\_only
100
141
 
101
142
  For times when Rails `distance_of_time_in_words` is not precise enough and `DOTIW` is too precise. For instance, if you only want to know the highest time part (measure) that elapsed between two dates.
102
143
 
103
- >> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.minute + 1.second, true, :highest_measure_only => true)
104
- => "1 hour"
144
+ ```ruby
145
+ >> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.minute + 1.second, true, highest_measure_only: true)
146
+ => "1 hour"
147
+ ```
105
148
 
106
149
  Notice how minutes and seconds were removed from the output. Another example:
107
150
 
108
- >> distance_of_time_in_words(Time.now, Time.now + 1.minute + 1.second, true, :highest_measure_only => true)
109
- => "1 minute"
151
+ ```ruby
152
+ >> distance_of_time_in_words(Time.now, Time.now + 1.minute + 1.second, true, highest_measure_only: true)
153
+ => "1 minute"
154
+ ```
110
155
 
111
156
  Minutes are the highest measure, so seconds were discarded from the output.
112
157
 
@@ -114,58 +159,97 @@ Minutes are the highest measure, so seconds were discarded from the output.
114
159
 
115
160
  When you want variable precision from `DOTIW`:
116
161
 
117
- >> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.minute + 1.second, true, :highest_measures => 2)
118
- => "1 hour and 1 minute"
162
+ ```ruby
163
+ >> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.minute + 1.second, true, highest_measures: 2)
164
+ => "1 hour and 1 minute"
165
+ ```
119
166
 
120
167
  #### :words_connector
121
168
 
122
- **This is an option for `to_sentence`, defaults to ', '**
169
+ This is an option for `to_sentence`, defaults to ', '.
123
170
 
124
171
  Using something other than a comma:
125
172
 
126
- >> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.minute + 1.second, true, :words_connector => ' - ')
127
- => "1 hour - 1 minute, and 1 second"
173
+ ```ruby
174
+ >> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.minute + 1.second, true, words_connector: ' - ')
175
+ => "1 hour - 1 minute, and 1 second"
176
+ ```
128
177
 
129
178
  #### :two\_words\_connector
130
179
 
131
- **This is an option for `to_sentence`, defaults to ' and '**
180
+ This is an option for `to_sentence`, defaults to ' and '.
132
181
 
133
182
  Using something other than 'and':
134
183
 
135
- >> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.minute, true, :two_words_connector => ' plus ')
136
- => "1 hour plus 1 minute"
184
+ ```ruby
185
+ >> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.minute, true, two_words_connector: ' plus ')
186
+ => "1 hour plus 1 minute"
187
+ ```
137
188
 
138
189
  #### :last\_word\_connector
139
190
 
140
- **This is an option for `to_sentence`, defaults to ', and '**
191
+ This is an option for `to_sentence`, defaults to ', and '.
141
192
 
142
193
  Using something other than ', and':
143
194
 
144
- >> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.minute + 1.second, true, :last_word_connector => ', finally ')
145
- => "1 hour, 1 minute, finally 1 second"
195
+ ```ruby
196
+ >> distance_of_time_in_words(Time.now, Time.now + 1.hour + 1.minute + 1.second, true, last_word_connector: ', finally ')
197
+ => "1 hour, 1 minute, finally 1 second"
198
+ ```
146
199
 
147
200
  ## distance\_of\_time
148
201
 
149
202
  If you have simply a number of seconds you can get the "stringified" version of this by using `distance_of_time`:
150
203
 
151
- >> distance_of_time(300)
152
- => "5 minutes"
204
+ ```ruby
205
+ >> distance_of_time(300)
206
+ => "5 minutes"
207
+ ```
153
208
 
154
209
  ## distance\_of\_time\_in\_words\_hash
155
210
 
156
211
  Don't like any format you're given? That's cool too! Here, have an indifferent hash version:
157
212
 
158
- >> distance_of_time_in_words_hash(Time.now, Time.now + 1.year + 2.months + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds)
159
- => {:days => 4, :weeks => 3, :seconds => 7, :minutes => 6, :years => 1, :hours => 5, :months => 2}
213
+ ```ruby
214
+ >> distance_of_time_in_words_hash(Time.now, Time.now + 1.year + 2.months + 3.weeks + 4.days + 5.hours + 6.minutes + 7.seconds)
215
+ => { days: 4, weeks: 3, seconds: 7, minutes: 6, years: 1, hours: 5, months: 2 }
216
+ ```
160
217
 
161
218
  Indifferent means that you can access all keys by their `String` or `Symbol` version.
162
219
 
163
220
  ## distance\_of\_time\_in\_percent
164
221
 
165
- If you want to calculate a distance of time in percent, use `distance_of_time_in_percent`. The first argument is the beginning time, the second argument the "current" time and the third argument is the end time. This method takes the same options as [`number_with_precision`](http://api.rubyonrails.org/classes/ActionView/Helpers/NumberHelper.html#method-i-number_with_precision).
222
+ This method is only available with Rails ActionView.
223
+
224
+ If you want to calculate a distance of time in percent, use `distance_of_time_in_percent`. The first argument is the beginning time, the second argument the "current" time and the third argument is the end time.
225
+
226
+ ```ruby
227
+ >> distance_of_time_in_percent("04-12-2009".to_time, "29-01-2010".to_time, "04-12-2010".to_time)
228
+ => '15%'
229
+ ```
230
+
231
+ This method takes the same options as [`number_with_precision`](http://api.rubyonrails.org/classes/ActionView/Helpers/NumberHelper.html#method-i-number_with_precision).
166
232
 
167
- distance_of_time_in_percent("04-12-2009".to_time, "29-01-2010".to_time, "04-12-2010".to_time, options)
233
+ ```ruby
234
+ >> distance_of_time_in_percent("04-12-2009".to_time, "29-01-2010".to_time, "04-12-2010".to_time, precision: 1)
235
+ => '15.3%'
236
+ ```
237
+
238
+ ## :compact
239
+
240
+ Pressed for space? Try `compact: true`.
241
+
242
+ ```ruby
243
+ >> distance_of_time_in_words(Time.now, Time.now + 2.year + 1.day + 1.second, compact: true)
244
+ => "2y1d"
245
+ ```
246
+
247
+ Pairs well with `words_connector`, `last_word_connector`, and `two_words_connector` if you can spare just a little more room:
168
248
 
249
+ ```ruby
250
+ >> distance_of_time_in_words(Time.now, Time.now + 5.years + 1.day + 23.seconds, words_connector: " ", last_word_connector: " ", two_words_connector: " ", compact: true)
251
+ => "5y 1d 23s"
252
+ ```
169
253
 
170
254
  ## Contributors
171
255
 
@@ -173,3 +257,4 @@ If you want to calculate a distance of time in percent, use `distance_of_time_in
173
257
  * [Derander](http://github.com/derander) - correct Spanish translations
174
258
  * [DBA](http://github.com/dba) - commits leading up to the 0.7 release
175
259
  * [Sija](http://github.com/Sija) - rails 4 support, v2.0 release
260
+ * [dblock](http://github.com/dblock) - Ruby w/o Rails support