humanize-bytes 2.0.1 → 2.1.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
  SHA1:
3
- metadata.gz: b822e696f285eb1cef5a3adc0a204264a9e18acf
4
- data.tar.gz: b6a0b750bdb3063662be4e4c998cea19dfe767e8
3
+ metadata.gz: 352f1ea83c8657e52cb904728a2590f16046d29d
4
+ data.tar.gz: 977d5f597321d04bd045c64a34964e1e482b811d
5
5
  SHA512:
6
- metadata.gz: 550886946965209414c1257ed751400961ce4454176b872e5b31775c350e429a0cbf14ec67eff914f4829c8ef97cf8896381c764eff3cf9ed3e231c8334b7464
7
- data.tar.gz: 6745bafdf1844cc8f252f40243a4bacd2b2e39e2dc733742be0e41cb4ad16265ff447b2533c51df0835e729e5b4db7472175812e46336be48abab78771a82f45
6
+ metadata.gz: ab986f567924b55a5c5fb7468e1e399fd1d088f7090813191a3f3ba00f0907d3b03831bedcbd160e5ad82deb52047bd948ece35938855b00f2f92e0408d6ca9e
7
+ data.tar.gz: b0052290ed4a4abfe29c9df40444c1b5b82a14455b68ca8df4b0ae71ab67cef48c86364f9ccfa4c46c3531e1f647a7934fcab4f714a94c020d04107cfce6f66d
@@ -1,13 +1,5 @@
1
1
  module Humanize
2
- class Byte
3
- def initialize(value)
4
- @value = value
5
- end
6
-
7
- def value
8
- @value
9
- end
10
-
2
+ class Byte < Bytes
11
3
  def to_b
12
4
  self
13
5
  end
@@ -23,11 +15,5 @@ module Humanize
23
15
  def to_g
24
16
  Giga.new @value / 1024.0 / 1024 / 1024
25
17
  end
26
-
27
- def to_s(options = {})
28
- size = options.fetch(:decimal_digits, nil)
29
- size ||= value.to_s.split('.').size == 1 ? 0 : value.to_s.split('.').last.size
30
- ("%.#{size}f" % value).to_s
31
- end
32
18
  end
33
19
  end
@@ -1,5 +1,20 @@
1
1
  module Humanize
2
2
  class Bytes
3
- VERSION = '2.0.1'
3
+ VERSION = '2.1.0'
4
+
5
+ def initialize(value)
6
+ @value = value.to_f
7
+ end
8
+
9
+ def value
10
+ @value
11
+ end
12
+
13
+ def to_s(options = {})
14
+ size = options.fetch(:decimal_digits, nil)
15
+ size ||= value.to_s.split('.').size == 1 ? 0 : value.to_s.split('.').last.size
16
+ size = 0 if value.to_s.split('.').size >= 2 and value.to_s.split('.').last.to_s == '0'
17
+ ("%.#{size}f" % value).to_s
18
+ end
4
19
  end
5
20
  end
@@ -1,13 +1,5 @@
1
1
  module Humanize
2
- class Giga
3
- def initialize(value)
4
- @value = value
5
- end
6
-
7
- def value
8
- @value
9
- end
10
-
2
+ class Giga < Bytes
11
3
  def to_b
12
4
  Byte.new @value * 1024 * 1024 * 1024
13
5
  end
@@ -23,11 +15,5 @@ module Humanize
23
15
  def to_g
24
16
  self
25
17
  end
26
-
27
- def to_s(options = {})
28
- size = options.fetch(:decimal_digits, nil)
29
- size ||= value.to_s.split('.').size == 1 ? 0 : value.to_s.split('.').last.size
30
- ("%.#{size}f" % value).to_s
31
- end
32
18
  end
33
19
  end
@@ -1,13 +1,5 @@
1
1
  module Humanize
2
- class Kilo
3
- def initialize(value)
4
- @value = value
5
- end
6
-
7
- def value
8
- @value
9
- end
10
-
2
+ class Kilo < Bytes
11
3
  def to_b
12
4
  Byte.new @value * 1024
13
5
  end
@@ -23,11 +15,5 @@ module Humanize
23
15
  def to_g
24
16
  Giga.new @value / 1024.0 / 1024
25
17
  end
26
-
27
- def to_s(options = {})
28
- size = options.fetch(:decimal_digits, nil)
29
- size ||= value.to_s.split('.').size == 1 ? 0 : value.to_s.split('.').last.size
30
- ("%.#{size}f" % value).to_s
31
- end
32
18
  end
33
19
  end
@@ -1,13 +1,5 @@
1
1
  module Humanize
2
- class Mega
3
- def initialize(value)
4
- @value = value
5
- end
6
-
7
- def value
8
- @value
9
- end
10
-
2
+ class Mega < Bytes
11
3
  def to_b
12
4
  Byte.new @value * 1024 * 1024
13
5
  end
@@ -23,11 +15,5 @@ module Humanize
23
15
  def to_g
24
16
  Giga.new @value / 1024.0
25
17
  end
26
-
27
- def to_s(options = {})
28
- size = options.fetch(:decimal_digits, nil)
29
- size ||= value.to_s.split('.').size == 1 ? 0 : value.to_s.split('.').last.size
30
- ("%.#{size}f" % value).to_s
31
- end
32
18
  end
33
19
  end
@@ -3,6 +3,12 @@ require 'spec_helper'
3
3
  describe Humanize::Byte do
4
4
  let(:b) { Humanize::Byte.new(2147843648) }
5
5
 
6
+ context "initialize" do
7
+ it "should convert the number to float" do
8
+ expect(Humanize::Byte.new('3').value).to be_an_instance_of(Float)
9
+ end
10
+ end
11
+
6
12
  context "#value" do
7
13
  it "should return the value" do
8
14
  expect(b.value).to eq(2147843648)
@@ -3,6 +3,12 @@ require 'spec_helper'
3
3
  describe Humanize::Giga do
4
4
  let(:g) { Humanize::Giga.new(3.25) }
5
5
 
6
+ context "initialize" do
7
+ it "should convert the number to float" do
8
+ expect(Humanize::Giga.new('3').value).to be_an_instance_of(Float)
9
+ end
10
+ end
11
+
6
12
  context "#value" do
7
13
  it "should return the value" do
8
14
  expect(g.value).to eq(3.25)
@@ -3,6 +3,12 @@ require 'spec_helper'
3
3
  describe Humanize::Kilo do
4
4
  let(:k) { Humanize::Kilo.new(5000) }
5
5
 
6
+ context "initialize" do
7
+ it "should convert the number to float" do
8
+ expect(Humanize::Kilo.new('3').value).to be_an_instance_of(Float)
9
+ end
10
+ end
11
+
6
12
  context "#value" do
7
13
  it "should return the value" do
8
14
  expect(k.value).to eq(5000)
@@ -3,6 +3,12 @@ require 'spec_helper'
3
3
  describe Humanize::Mega do
4
4
  let(:m) { Humanize::Mega.new(4.8828125) }
5
5
 
6
+ context "initialize" do
7
+ it "should convert the number to float" do
8
+ expect(Humanize::Mega.new('3').value).to be_an_instance_of(Float)
9
+ end
10
+ end
11
+
6
12
  context "#value" do
7
13
  it "should return the value" do
8
14
  expect(m.value).to eq(4.8828125)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: humanize-bytes
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paulo Henrique Lopes Ribeiro
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-11 00:00:00.000000000 Z
11
+ date: 2014-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake