humane 0.9.3 → 0.9.4
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.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/humane/size.rb +14 -9
- data/lib/humane/time.rb +1 -1
- data/lib/humane/version.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2f883bfabda57dd323ebb94f44125d02e2fa00679bcc13c4063e5d0e4a48c539
|
|
4
|
+
data.tar.gz: 1aad3e0fc5ff805ec0538e7b7c505d9867f68885ee50b8cb0c9477f540d17072
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ee35cb014e3d0e6f300e739c1501d4acd305d25d5fb978bc7435a454650caafa66549bb4095dce613974c4756de3d234743fa1662e5cfae11925b652168501ed
|
|
7
|
+
data.tar.gz: 44e8aea529335b127adb38019941cd110625858c6b789e2af4242b48e862a27f3d620e865430322bbe83bfb9339e9897d56102128951e29e4fee1d61b75fdf45
|
data/README.md
CHANGED
|
@@ -63,7 +63,7 @@ Humane.time_ago(at) # same defaults, relative_to is Time.no
|
|
|
63
63
|
- **`include_seconds`** (default `false`): under 30 seconds, collapses to
|
|
64
64
|
`"less than a minute ago"`/`"in less than a minute"` instead of an exact
|
|
65
65
|
second count. Matches ActionView's `include_seconds` default.
|
|
66
|
-
- **`when_nil`** (default `
|
|
66
|
+
- **`when_nil`** (default `""`): if `at` is `nil`, both methods return this
|
|
67
67
|
value without formatting -- for a scan, download, or other record that
|
|
68
68
|
doesn't have a timestamp yet.
|
|
69
69
|
|
data/lib/humane/size.rb
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
module Humane
|
|
4
4
|
UNITS = %w[KB MB GB TB PB EB].freeze
|
|
5
|
+
DECIMAL_PLACES = [0, 1, 2, 2, 2, 2].freeze
|
|
5
6
|
|
|
6
7
|
# Returns byte_count as a Finder-style human-readable string.
|
|
7
8
|
#
|
|
@@ -11,20 +12,24 @@ module Humane
|
|
|
11
12
|
return (byte_count == 1) ? "1 byte" : "#{byte_count} bytes" if byte_count < 1000
|
|
12
13
|
|
|
13
14
|
exponent = [(Math.log(byte_count) / Math.log(1000)).to_i, UNITS.size].min
|
|
14
|
-
value = byte_count
|
|
15
|
+
value = round_for_unit(byte_count, exponent)
|
|
16
|
+
if value >= 1000 && exponent < UNITS.size
|
|
17
|
+
exponent += 1
|
|
18
|
+
value = round_for_unit(byte_count, exponent)
|
|
19
|
+
end
|
|
15
20
|
|
|
16
|
-
"#{
|
|
21
|
+
"#{trim_zeros(value, DECIMAL_PLACES[exponent - 1])} #{UNITS[exponent - 1]}"
|
|
17
22
|
end
|
|
18
23
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
decimals = [sig_figs - magnitude, 0].max
|
|
24
|
+
def self.round_for_unit(byte_count, exponent)
|
|
25
|
+
scale = 10**DECIMAL_PLACES[exponent - 1]
|
|
26
|
+
(byte_count / (1000.0**exponent) * scale).round / scale.to_f
|
|
27
|
+
end
|
|
28
|
+
private_class_method :round_for_unit
|
|
25
29
|
|
|
30
|
+
def self.trim_zeros(value, decimals)
|
|
26
31
|
formatted = format("%.#{decimals}f", value)
|
|
27
32
|
formatted.include?(".") ? formatted.sub(/0+\z/, "").sub(/\.\z/, "") : formatted
|
|
28
33
|
end
|
|
29
|
-
private_class_method :
|
|
34
|
+
private_class_method :trim_zeros
|
|
30
35
|
end
|
data/lib/humane/time.rb
CHANGED
|
@@ -9,7 +9,7 @@ module Humane
|
|
|
9
9
|
# one-argument convenience. See docs/COMMENTS.md.
|
|
10
10
|
#
|
|
11
11
|
# Humane.distance_in_time(Time.now - 180, Time.now) #=> "3 minutes ago"
|
|
12
|
-
def self.distance_in_time(at, relative_to, approximate: true, include_seconds: false, when_nil:
|
|
12
|
+
def self.distance_in_time(at, relative_to, approximate: true, include_seconds: false, when_nil: "")
|
|
13
13
|
return when_nil if at.nil?
|
|
14
14
|
|
|
15
15
|
seconds = relative_to - at
|
data/lib/humane/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: humane
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.9.
|
|
4
|
+
version: 0.9.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- John Woodell
|
|
8
|
+
autorequire:
|
|
8
9
|
bindir: bin
|
|
9
10
|
cert_chain: []
|
|
10
|
-
date:
|
|
11
|
+
date: 2026-10-12 00:00:00.000000000 Z
|
|
11
12
|
dependencies: []
|
|
12
13
|
description: Finder-style file sizes and ActionView-flavored relative dates for Ruby,
|
|
13
14
|
consistent with the humane (Go) and humane-swift siblings.
|
|
@@ -29,6 +30,7 @@ licenses:
|
|
|
29
30
|
metadata:
|
|
30
31
|
homepage_uri: https://github.com/woodie/humane-ruby
|
|
31
32
|
source_code_uri: https://github.com/woodie/humane-ruby
|
|
33
|
+
post_install_message:
|
|
32
34
|
rdoc_options: []
|
|
33
35
|
require_paths:
|
|
34
36
|
- lib
|
|
@@ -43,7 +45,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
43
45
|
- !ruby/object:Gem::Version
|
|
44
46
|
version: '0'
|
|
45
47
|
requirements: []
|
|
46
|
-
rubygems_version: 3.
|
|
48
|
+
rubygems_version: 3.5.22
|
|
49
|
+
signing_key:
|
|
47
50
|
specification_version: 4
|
|
48
51
|
summary: Finder-style file sizes and relative dates, as simple as ActionView
|
|
49
52
|
test_files: []
|