friendly_numbers 0.2.0 → 0.3.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
  SHA1:
3
- metadata.gz: 083f9bc78bce7405ff3be9b4c98d54f513d51656
4
- data.tar.gz: d8ae616f668ef23ca2cda1e03747a698c5e9acf0
3
+ metadata.gz: 97dfbb299d7c618df8fa9acfc1345de6a55697ea
4
+ data.tar.gz: f98f23f9c9636ae41eefc3ffc0730235e1dc0250
5
5
  SHA512:
6
- metadata.gz: fce62b13582d6a10918e2678dbdc261ec1ebb084f6254b21a37ebc8c038475902b63729ae9ad01f8db323b16c441f80e89d17036a9d0bb768aa8a147a293d4f8
7
- data.tar.gz: ff0a37dbcf10e3252d09259fb95db65f98f51ea18f0b34d9e6844ac76d78200ad61bc4617c995ac7feaf9cef09eec22afbc8e4d3f40e6c1e4140a7d759b7be92
6
+ metadata.gz: 9d057dd64cd6ea14272cfcc2b5b13004735e866063596313bc5e8eb3b709e130010e50f759169e335aa60f1f19c6b241729349d2cde2d2deab43e7954f557617
7
+ data.tar.gz: aae84bbd59e47d0bcf39e822f1be3adef8f7ef0c49574a6a0b088a98a6b66492cc137aaada0d8d3a827ff8c5beaeab01cefd232e0a371423e856de95a2c8be0b
data/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ # master
2
+
3
+ # 0.3.0 (2017-04-22)
4
+ - Add seconds_to_time helper.
5
+
6
+ # 0.2.0
7
+ - Add number_to_percentage helper.
8
+ - Separate currency into thousands.
9
+
10
+ # 0.1.0
11
+ - Add number_to_currency helper.
12
+ - Add number_to_human_size helper.
data/README.md CHANGED
@@ -31,6 +31,10 @@ To format a value as a human file size:
31
31
 
32
32
  FriendlyNumbers.number_to_human_size 12345.67 # => "12.056 KB"
33
33
 
34
+ To format time in seconds to an elapsed time:
35
+
36
+ FriendlyNumbers.seconds_to_time(65) # => "1m 5s"
37
+
34
38
  Also conveniently aliased under the `Friendly` namespace.
35
39
 
36
40
  ## Development
@@ -2,6 +2,7 @@ require "friendly_numbers/version"
2
2
  require "friendly_numbers/number_to_currency"
3
3
  require "friendly_numbers/number_to_human_size"
4
4
  require "friendly_numbers/number_to_percentage"
5
+ require "friendly_numbers/seconds_to_time"
5
6
 
6
7
  module FriendlyNumbers
7
8
  module_function
@@ -32,6 +33,15 @@ module FriendlyNumbers
32
33
  def number_to_percentage(value, options = {})
33
34
  NumberToPercentage.convert(value, options)
34
35
  end
36
+
37
+ # Convert Seconds to an elapsed time
38
+ #
39
+ # Options:
40
+ # format:: a callable object that receives hours, minutes, seconds as
41
+ # arguments
42
+ def seconds_to_time(seconds, options = {})
43
+ SecondsToTime.convert(seconds, options)
44
+ end
35
45
  end
36
46
 
37
47
  Friendly = FriendlyNumbers
@@ -0,0 +1,27 @@
1
+ module FriendlyNumbers
2
+ module SecondsToTime
3
+ DEFAULTS = {
4
+ format: ->(hours, minutes, seconds) {
5
+ fields = []
6
+ fields.push("#{hours}h") unless hours.zero?
7
+ fields.push("#{minutes}m") unless minutes.zero?
8
+ fields.push("#{seconds}s") if seconds
9
+
10
+ fields.join(" ")
11
+ }
12
+ }
13
+
14
+ module_function
15
+
16
+ def convert(seconds, options) # :nodoc:
17
+ options = DEFAULTS.merge(options)
18
+
19
+ minutes, seconds = seconds.divmod(60)
20
+ hours, minutes = minutes.divmod(60)
21
+
22
+ if options[:format].respond_to?(:call)
23
+ options[:format].call(hours, minutes, seconds)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,3 +1,3 @@
1
1
  module FriendlyNumbers
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: friendly_numbers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Daniels
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-11 00:00:00.000000000 Z
11
+ date: 2017-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -65,6 +65,7 @@ extra_rdoc_files: []
65
65
  files:
66
66
  - ".gitignore"
67
67
  - ".travis.yml"
68
+ - CHANGELOG.md
68
69
  - Gemfile
69
70
  - LICENSE.txt
70
71
  - README.md
@@ -76,6 +77,7 @@ files:
76
77
  - lib/friendly_numbers/number_to_currency.rb
77
78
  - lib/friendly_numbers/number_to_human_size.rb
78
79
  - lib/friendly_numbers/number_to_percentage.rb
80
+ - lib/friendly_numbers/seconds_to_time.rb
79
81
  - lib/friendly_numbers/version.rb
80
82
  homepage: https://github.com/adam12/friendly_numbers
81
83
  licenses: