activesupport-duration-human_string 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7a7049bf99ad5f6ffbf07e5ae95ae38efea3b73b9b57dfaf9f655ac66ddb2338
4
- data.tar.gz: ed4fa6793ec9549bd7379120b325e2a5b27c338dfc0d5728168c3d84abc407e6
3
+ metadata.gz: 7a42d606d1f8510d965e98436ecb7232868bf0f00053da7cb7f6f430c0dd2321
4
+ data.tar.gz: c1c817cf2dcec49125adad4fc6c05f45331a255ec112b52e90926296aea1f45a
5
5
  SHA512:
6
- metadata.gz: b960130471d06f5cf4425b3e53158e23094703cbd4c5efbed04d4cac133628d2662ac3a8ad742f2fd1971e4edddbd54551d465c8d57b01986ce983ce3412623d
7
- data.tar.gz: 8b1b76dbb70d9d31f7637b7f09c03857b15643b8eb8a3f35de1615e7df420dd18622674744ecea6fc77df865c56b7fe39d7f88b9c5bf2f602dc667cbe1d54c62
6
+ metadata.gz: 8705aed9bc654ba6667ad5b9c9ebe99931f479846c24fd2a5112ca848cee2f438b95746b8ef96296e7f5d6f50d677369d2f9d6d13f578e2f17cc2ef8b1d26d94
7
+ data.tar.gz: 29d6639d5c7131b4db0b8f7a8b48a3155c245169b53838d163c6bd308231e15e723a9630d46de119462a8315ae40f4c791403390b46f715d96419cfc6eb88a27
data/.gitignore CHANGED
@@ -6,6 +6,7 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ /vendor/
9
10
 
10
11
  # rspec failure tracking
11
12
  .rspec_status
data/Changelog.md CHANGED
@@ -0,0 +1,14 @@
1
+ ## 1.0.0 (2024-02-16)
2
+
3
+ Fixes:
4
+
5
+ - Relax activesupport dependency version
6
+
7
+ Breaking changes:
8
+
9
+ - Extract `#change`, `#truncate`, `#round`, etc. out of this gem into the [activesupport-duration-change](https://github.com/TylerRick/activesupport-duration-change) gem
10
+
11
+ ## 0.1.1 (2019-04-02)
12
+
13
+ Initial release
14
+
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in activesupport-duration-human_string.gemspec
4
4
  gemspec
5
+
6
+ gem 'byebug'
data/Readme.md CHANGED
@@ -1,10 +1,21 @@
1
- # `ActiveSupport::Duration#human_string`
2
-
3
- Convert [ActiveSupport::Duration](https://api.rubyonrails.org/classes/ActiveSupport/Duration.html) objects to human-friendly strings like `'2h 30m 17s'`.
4
-
5
- - Like [`distance_of_time_in_words`](https://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html) helper but _exact_ rather than approximate.
6
- - Like [`#inspect`](https://github.com/rails/rails/blob/b9ca94caea2ca6a6cc09abaffaad67b447134079/activesupport/lib/active_support/duration.rb#L372) but more concise and configurable.
7
- - Like [`#iso8601`](https://api.rubyonrails.org/classes/ActiveSupport/Duration.html#method-i-iso8601) but more human readable rather than machine readable.
1
+ # ActiveSupport::Duration#human_string [![Gem Version](https://badge.fury.io/rb/activesupport-duration-human_string.svg)](https://badge.fury.io/rb/activesupport-duration-human_string)
2
+
3
+ Convert [ActiveSupport::Duration](https://api.rubyonrails.org/classes/ActiveSupport/Duration.html)
4
+ objects to human-friendly strings like `'2h 30m 17s'` or `'3y 6m 4d 12h 30m 5s'`.
5
+
6
+ - Like [`distance_of_time_in_words`](https://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html#method-i-distance_of_time_in_words)
7
+ helper but _exact_ rather than approximate
8
+ - `distance_of_time_in_words` is somewhat configurable but only gives an approximation (`'over 3
9
+ years'`), with no option to print the exact number of each units.
10
+ - Like [`#inspect`](https://github.com/rails/rails/blob/b9ca94caea2ca6a6cc09abaffaad67b447134079/activesupport/lib/active_support/duration.rb#L372)
11
+ but more concise and configurable.
12
+ - `#inspect` is long (`'3 years, 6 months, 4 days, 12 hours, 30 minutes, and 5 seconds'`) and not
13
+ at all configurable.
14
+ - Like [`#iso8601`](https://api.rubyonrails.org/classes/ActiveSupport/Duration.html#method-i-iso8601)
15
+ but more human readable rather than machine readable.
16
+ - `#iso8601` is concise and machine-readable, but not very human-readable (`'P3Y6M4DT12H30M5S'`)!
17
+ - Unlike [`#to_s`](https://api.rubyonrails.org/classes/ActiveSupport/Duration.html#method-i-to_s),
18
+ which is very concise (`'110839937'`) but not at all human-readable for large durations
8
19
 
9
20
  ## Installation
10
21
 
@@ -17,19 +28,26 @@ gem 'activesupport-duration-human_string'
17
28
  ## Usage
18
29
 
19
30
  ```ruby
20
- duration = ActiveSupport::Duration.build(65)
21
- duration.human_str # => '1m 5s'
22
- duration.human_str(use_2_digit_numbers: true) # => '1m 05s'
23
-
24
- duration = ActiveSupport::Duration.build(3500)
31
+ duration = 3500.seconds
25
32
  duration.human_str # => '58m 20s'
26
33
  duration.human_str(delimiter: '') # => '58m20s'
27
34
  duration.human_str(separator: ' ') # => '58 m 20 s'
28
35
  duration.human_str(delimiter: ', ', separator: ' ') # => '58 m, 20 s'
36
+
37
+ duration = ActiveSupport::Duration.parse "P3Y6M4DT12H30M5S"
38
+ # => 3 years, 6 months, 4 days, 12 hours, 30 minutes, and 5 seconds
39
+
40
+ duration.human_str # => "3y 6m 4d 12h 30m 5s"
41
+ (duration - 4.days).human_str # => "3y 6m 12h 30m 5s"
42
+ duration.human_str(delimiter: ', ') # => "3y, 6m, 4d, 12h, 30m, 5s"
29
43
  ```
30
44
 
31
45
  Also aliased as `human_string`, `to_human_s`.
32
46
 
47
+ ## See also
48
+
49
+ - [activesupport-duration-change](https://github.com/TylerRick/activesupport-duration-change), which adds methods such as `#change`, `#truncate`, `#round` to `Duration`
50
+
33
51
  ## Development
34
52
 
35
53
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -40,7 +58,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
40
58
 
41
59
  Bug reports and pull requests are welcome on GitHub at https://github.com/TylerRick/activesupport-duration-human_string.
42
60
 
43
- ## Not really related
61
+ ## Not really related
44
62
 
45
63
  - https://github.com/josedonizetti/ruby-duration
46
64
  - https://github.com/janko/as-duration
@@ -30,9 +30,9 @@ Gem::Specification.new do |spec|
30
30
  spec.require_paths = ["lib"]
31
31
 
32
32
  spec.required_ruby_version = ">= 2.3.0"
33
- spec.add_dependency "activesupport", [">= 4.2", "< 5.3"]
33
+ spec.add_dependency "activesupport", [">= 5.2"]
34
34
 
35
- spec.add_development_dependency "bundler", "~> 2.0"
36
- spec.add_development_dependency "rake", "~> 10.0"
37
- spec.add_development_dependency "rspec", "~> 3.0"
35
+ spec.add_development_dependency "bundler"
36
+ spec.add_development_dependency "rake"
37
+ spec.add_development_dependency "rspec"
38
38
  end
@@ -1,9 +1,9 @@
1
1
  module ActiveSupport
2
2
  class Duration
3
3
  module HumanString
4
- def self.version
5
- "0.1.0"
6
- end
4
+ def self.version
5
+ "1.0.0"
6
+ end
7
7
  end
8
8
  end
9
9
  end
@@ -1,27 +1,35 @@
1
+ require 'active_support'
1
2
  require 'active_support/duration'
2
3
  require 'active_support/duration/iso8601_serializer'
3
4
 
4
5
  module ActiveSupport
5
6
  class Duration
6
- # Convert [ActiveSupport::Duration](https://api.rubyonrails.org/classes/ActiveSupport/Duration.html) objects to human-friendly strings like `'2h 30m 17s'`.
7
+ # Convert [ActiveSupport::Duration](https://api.rubyonrails.org/classes/ActiveSupport/Duration.html)
8
+ # objects to human-friendly strings like `'2h 30m 17s'` or `'3y 6m 4d 12h 30m 5s'`.
7
9
  #
8
- # Like [`distance_of_time_in_words`](https://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html) helper but _exact_ rather than approximate.
9
- # Like `#inspect` but more concise. Like [`#iso8601`](https://api.rubyonrails.org/classes/ActiveSupport/Duration.html#method-i-iso8601) but more human readable rather than machine readable.
10
+ # - Like [`distance_of_time_in_words`](https://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html) helper but _exact_ rather than approximate.
11
+ # - Like [`#inspect`](https://github.com/rails/rails/blob/b9ca94caea2ca6a6cc09abaffaad67b447134079/activesupport/lib/active_support/duration.rb#L372) but more concise and configurable.
12
+ # - Like [`#iso8601`](https://api.rubyonrails.org/classes/ActiveSupport/Duration.html#method-i-iso8601) but more human readable rather than machine readable.
10
13
  #
11
14
  # Note that the unit 'm' is used for both months and minutes.
12
15
  #
13
16
  # ## Examples
14
17
  #
15
- # duration = ActiveSupport::Duration.build(65)
16
- # duration.human_str # => '1m 5s'
17
- # duration.human_str(use_2_digit_numbers: true) # => '1m 05s'
18
- #
19
- # duration = ActiveSupport::Duration.build(3500)
18
+ # ```ruby
19
+ # duration = 3500.seconds
20
20
  # duration.human_str # => '58m 20s'
21
21
  # duration.human_str(delimiter: '') # => '58m20s'
22
22
  # duration.human_str(separator: ' ') # => '58 m 20 s'
23
23
  # duration.human_str(delimiter: ', ', separator: ' ') # => '58 m, 20 s'
24
24
  #
25
+ # duration = ActiveSupport::Duration.parse "P3Y6M4DT12H30M5S"
26
+ # # => 3 years, 6 months, 4 days, 12 hours, 30 minutes, and 5 seconds
27
+ #
28
+ # duration.human_str # => "3y 6m 4d 12h 30m 5s"
29
+ # (duration - 4.days).human_str # => "3y 6m 12h 30m 5s"
30
+ # duration.human_str(delimiter: ', ') # => "3y, 6m, 4d, 12h, 30m, 5s"
31
+ # ```
32
+ #
25
33
  # ## Options
26
34
  #
27
35
  # `:precision`: Precision of seconds (defaults to nil, which is no digits after decimal).
@@ -35,7 +43,7 @@ module ActiveSupport
35
43
  #
36
44
  def human_str(precision: nil, separator: '', delimiter: ' ', use_2_digit_numbers: false)
37
45
  HumanStringSerializer.new(
38
- self,
46
+ self.class.build(value),
39
47
  precision: precision,
40
48
  separator: separator,
41
49
  delimiter: delimiter,
@@ -0,0 +1 @@
1
+ require 'active_support/duration/human_string'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activesupport-duration-human_string
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Rick
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-04-02 00:00:00.000000000 Z
11
+ date: 2024-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,62 +16,56 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4.2'
20
- - - "<"
21
- - !ruby/object:Gem::Version
22
- version: '5.3'
19
+ version: '5.2'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - ">="
28
25
  - !ruby/object:Gem::Version
29
- version: '4.2'
30
- - - "<"
31
- - !ruby/object:Gem::Version
32
- version: '5.3'
26
+ version: '5.2'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: bundler
35
29
  requirement: !ruby/object:Gem::Requirement
36
30
  requirements:
37
- - - "~>"
31
+ - - ">="
38
32
  - !ruby/object:Gem::Version
39
- version: '2.0'
33
+ version: '0'
40
34
  type: :development
41
35
  prerelease: false
42
36
  version_requirements: !ruby/object:Gem::Requirement
43
37
  requirements:
44
- - - "~>"
38
+ - - ">="
45
39
  - !ruby/object:Gem::Version
46
- version: '2.0'
40
+ version: '0'
47
41
  - !ruby/object:Gem::Dependency
48
42
  name: rake
49
43
  requirement: !ruby/object:Gem::Requirement
50
44
  requirements:
51
- - - "~>"
45
+ - - ">="
52
46
  - !ruby/object:Gem::Version
53
- version: '10.0'
47
+ version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
51
  requirements:
58
- - - "~>"
52
+ - - ">="
59
53
  - !ruby/object:Gem::Version
60
- version: '10.0'
54
+ version: '0'
61
55
  - !ruby/object:Gem::Dependency
62
56
  name: rspec
63
57
  requirement: !ruby/object:Gem::Requirement
64
58
  requirements:
65
- - - "~>"
59
+ - - ">="
66
60
  - !ruby/object:Gem::Version
67
- version: '3.0'
61
+ version: '0'
68
62
  type: :development
69
63
  prerelease: false
70
64
  version_requirements: !ruby/object:Gem::Requirement
71
65
  requirements:
72
- - - "~>"
66
+ - - ">="
73
67
  - !ruby/object:Gem::Version
74
- version: '3.0'
68
+ version: '0'
75
69
  description: 'Convert ActiveSupport::Duration objects to human-friendly strings like
76
70
  ''2h 30m 17s''. '
77
71
  email:
@@ -93,6 +87,7 @@ files:
93
87
  - bin/setup
94
88
  - lib/active_support/duration/human_string.rb
95
89
  - lib/active_support/duration/human_string/version.rb
90
+ - lib/activesupport-duration-human_string.rb
96
91
  homepage: https://github.com/TylerRick/activesupport-duration-human_string
97
92
  licenses:
98
93
  - MIT
@@ -115,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
110
  - !ruby/object:Gem::Version
116
111
  version: '0'
117
112
  requirements: []
118
- rubygems_version: 3.0.1
113
+ rubygems_version: 3.5.1
119
114
  signing_key:
120
115
  specification_version: 4
121
116
  summary: Convert Duration objects to human-friendly strings like '2h 30m 17s'