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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 94b64259f8b2dc0d78f3f6feb6b48b4d908f23bfa74f133d901c57f5232294bd
4
- data.tar.gz: 65e61cee90061fb0eba0e08053c2d24104d7e7d8bc711b8789661a5b27dd9f52
3
+ metadata.gz: 9f1d568f746432126417fdd6541c249d81475c663e4e9ae9a772fcbc1dc59e3f
4
+ data.tar.gz: f85e12c6dbd402a4a1d452ba4629e6921418ff8609d6222333b17c1b51ae6a05
5
5
  SHA512:
6
- metadata.gz: a3320656c10207ff6e941325d26085bc16acb4a56807cf4daafd2bb7560396cd36a37afcc77b270114b330d83ae9e0a7b8b394444958b0a7f96207a775c9492a
7
- data.tar.gz: 84d09dac947371900807718502d17055a914b91e58833a10fc2868c0179794fbf8ba80a42d14b359aef4fa4c32c2dbdcaa9265d737195f90c7978bc381a2dce2
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
- Two options on `Humane::TimeFormatter`, both off by default so it matches
56
- `RelativeDateTimeFormatter` exactly out of the box:
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 the time at `at` relative to `relative_to` as a human-readable string.
14
- def string(at:, relative_to:)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Humane
4
- VERSION = "0.5.0"
4
+ VERSION = "0.6.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: humane
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Woodell