humane 0.5.0 → 0.6.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.
- checksums.yaml +4 -4
- data/README.md +13 -2
- data/lib/humane/size_formatter.rb +5 -2
- data/lib/humane/time_formatter.rb +7 -2
- data/lib/humane/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9f1d568f746432126417fdd6541c249d81475c663e4e9ae9a772fcbc1dc59e3f
|
|
4
|
+
data.tar.gz: f85e12c6dbd402a4a1d452ba4629e6921418ff8609d6222333b17c1b51ae6a05
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fa9e176a20d540c3c325c6f1015c2353b2fbced72397d9bcb645eea021129341781543399ac0a94d1cde5b885e64738e7d723d14c2bfb8548c3b7f7d392664cd
|
|
7
|
+
data.tar.gz: e59a7270df069333babc2d10f6234bbb507853b9b2c1583e437e41f1451a1f0dd6bc82cba1f88ec83989bb31a2957132f8d8c38a4bd96a056fb1a1b293ebd39f
|
data/README.md
CHANGED
|
@@ -22,6 +22,14 @@ time_formatter = Humane::TimeFormatter.new
|
|
|
22
22
|
time_formatter.string(at: Time.now - 180, relative_to: Time.now) # "3 minutes ago"
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
+
Both methods also accept positional arguments, matching `humane` (Go)'s
|
|
26
|
+
positional-only calling convention:
|
|
27
|
+
|
|
28
|
+
```ruby
|
|
29
|
+
Humane::SizeFormatter.new.string(225_935) # "226 KB"
|
|
30
|
+
time_formatter.string(Time.now - 180, Time.now) # "3 minutes ago"
|
|
31
|
+
```
|
|
32
|
+
|
|
25
33
|
Corresponding functions in Swift will have consistent output.
|
|
26
34
|
|
|
27
35
|
```swift
|
|
@@ -52,8 +60,11 @@ gem "humane"
|
|
|
52
60
|
|
|
53
61
|
## Beyond Foundation's defaults
|
|
54
62
|
|
|
55
|
-
|
|
56
|
-
`
|
|
63
|
+
Foundation is the baseline every default matches exactly, in all three
|
|
64
|
+
languages -- these two options on `Humane::TimeFormatter` are how you layer
|
|
65
|
+
ActionView's wording on top of it, not a replacement for it. Both off by
|
|
66
|
+
default, so `Humane::TimeFormatter.new` and calling `RelativeDateTimeFormatter`
|
|
67
|
+
directly always agree:
|
|
57
68
|
|
|
58
69
|
- `include_seconds` (default `false`): under 30 seconds, collapses to "less than a
|
|
59
70
|
minute ago"/"in less than a minute" instead of an exact second count. Named after
|
|
@@ -5,8 +5,11 @@ module Humane
|
|
|
5
5
|
class SizeFormatter
|
|
6
6
|
UNITS = %w[B KB MB GB TB PB EB].freeze
|
|
7
7
|
|
|
8
|
-
# Returns from_byte_count as a Finder-style human-readable string.
|
|
9
|
-
def string(from_byte_count:)
|
|
8
|
+
# Returns from_byte_count as a Finder-style human-readable string; accepts positional or from_byte_count: keyword argument -- see docs/COMMENTS.md.
|
|
9
|
+
def string(positional_from_byte_count = nil, from_byte_count: nil)
|
|
10
|
+
from_byte_count ||= positional_from_byte_count
|
|
11
|
+
raise ArgumentError, "from_byte_count is required" unless from_byte_count
|
|
12
|
+
|
|
10
13
|
return "#{from_byte_count} B" if from_byte_count < 1000
|
|
11
14
|
|
|
12
15
|
exponent = [(Math.log(from_byte_count) / Math.log(1000)).to_i, UNITS.size - 1].min
|
|
@@ -10,8 +10,13 @@ module Humane
|
|
|
10
10
|
@approximate = approximate
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
-
# Returns
|
|
14
|
-
def string(at
|
|
13
|
+
# Returns at relative to relative_to; accepts positional or at:/relative_to: keyword arguments -- see docs/COMMENTS.md.
|
|
14
|
+
def string(positional_at = nil, positional_relative_to = nil, at: nil, relative_to: nil)
|
|
15
|
+
at ||= positional_at
|
|
16
|
+
relative_to ||= positional_relative_to
|
|
17
|
+
raise ArgumentError, "at is required" unless at
|
|
18
|
+
raise ArgumentError, "relative_to is required" unless relative_to
|
|
19
|
+
|
|
15
20
|
seconds = relative_to - at
|
|
16
21
|
future = seconds.negative?
|
|
17
22
|
seconds = seconds.abs
|
data/lib/humane/version.rb
CHANGED