humanize-bytes 2.1.0 → 2.2.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: 352f1ea83c8657e52cb904728a2590f16046d29d
4
- data.tar.gz: 977d5f597321d04bd045c64a34964e1e482b811d
3
+ metadata.gz: 695dd5f96cad7054596aa8d4d7b581a6e527afae
4
+ data.tar.gz: 4ed8d62982c3847555b174d826458d352c418ac7
5
5
  SHA512:
6
- metadata.gz: ab986f567924b55a5c5fb7468e1e399fd1d088f7090813191a3f3ba00f0907d3b03831bedcbd160e5ad82deb52047bd948ece35938855b00f2f92e0408d6ca9e
7
- data.tar.gz: b0052290ed4a4abfe29c9df40444c1b5b82a14455b68ca8df4b0ae71ab67cef48c86364f9ccfa4c46c3531e1f647a7934fcab4f714a94c020d04107cfce6f66d
6
+ metadata.gz: 125db803fedd3bfa9a60228790477e85eb2cb385d0972f91b5a1017e2d6f790eae88c68c394d2cf3a6711549378e12af7ce6f2caf416c34d7feef765cb1944df
7
+ data.tar.gz: 65e9c78792058a16e9b154e22181c52568af96a766b66868a1455b5bf12390e93bbf3432ca19e998cd86d394247557675bb4c9d517c7e8268409220862ffad0a
@@ -1 +1 @@
1
- 2.1.2
1
+ 2.2.3
@@ -4,4 +4,8 @@ rvm:
4
4
  - 1.9.3
5
5
  - 2.0
6
6
  - 2.1.2
7
- - jruby
7
+ - 2.2.3
8
+ - jruby
9
+
10
+ before_install:
11
+ - gem update bundler
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Humanize::Bytes [![Build Status](https://secure.travis-ci.org/plribeiro3000/humanize-bytes.png)](http://travis-ci.org/plribeiro3000/humanize-bytes)
2
2
 
3
- Convert Byte, Kbyte, MByte, Gbyte into each other easy as to_b.
3
+ Convert Byte, KByte, MByte, GByte, TByte, PByte, EByte, ZByte and YByte into each other easy as to_b.
4
4
 
5
5
  ## Installation
6
6
 
@@ -24,7 +24,19 @@ Initialize a New Byte Object with
24
24
  Humanize::Byte.new(1024)
25
25
  ```
26
26
 
27
- Then call one of the methods: to_b, to_k, to_m, to_g.
27
+ ## Conversion Table
28
+
29
+ | Value | Equivalent | Call Methods |
30
+ |-------|------------|:-----------:|
31
+ | Byte | 1 Byte | to_b |
32
+ | Kilobyte | 1024 Bytes | to_k |
33
+ | Megabyte | 1024 Kilobytes | to_m |
34
+ | Gigabyte | 1024 Megabytes | to_g |
35
+ | Terabyte | 1024 Gigabytes | to_t |
36
+ | Petabyte | 1024 Terabytes | to_p |
37
+ | Exabyte | 1024 Petabytes | to_e |
38
+ | Zettabyte | 1024 Exabytes | to_z |
39
+ | Yottabyte | 1024 Zettabytes | to_y |
28
40
 
29
41
  ## Contributing
30
42
 
@@ -8,7 +8,7 @@ Gem::Specification.new do |gem|
8
8
  gem.version = Humanize::Bytes::VERSION
9
9
  gem.authors = %q{Paulo Henrique Lopes Ribeiro}
10
10
  gem.email = %q{plribeiro3000@gmail.com}
11
- gem.summary = %q{Convert Byte, Kbyte, MByte, Gbyte into each other}
11
+ gem.summary = %q{Convert Byte, KByte, MByte, GByte, TByte, PByte, EByte, ZByte and YByte into each other}
12
12
 
13
13
  gem.files = `git ls-files`.split($\)
14
14
  gem.test_files = `git ls-files -- {test,spec,features,examples,gemfiles}/*`.split("\n")
@@ -4,4 +4,9 @@ module Humanize
4
4
  autoload :Kilo, 'humanize/kilo'
5
5
  autoload :Mega, 'humanize/mega'
6
6
  autoload :Giga, 'humanize/giga'
7
+ autoload :Tera, 'humanize/tera'
8
+ autoload :Peta, 'humanize/peta'
9
+ autoload :Exa, 'humanize/exa'
10
+ autoload :Zetta, 'humanize/zetta'
11
+ autoload :Yotta, 'humanize/yotta'
7
12
  end
@@ -15,5 +15,25 @@ module Humanize
15
15
  def to_g
16
16
  Giga.new @value / 1024.0 / 1024 / 1024
17
17
  end
18
+
19
+ def to_t
20
+ Tera.new @value / 1024.0 / 1024.0 / 1024.0 / 1024.0
21
+ end
22
+
23
+ def to_p
24
+ Peta.new @value / 1024.0 / 1024.0 / 1024.0 / 1024.0 / 1024.0
25
+ end
26
+
27
+ def to_e
28
+ Exa.new @value / 1024.0 / 1024.0 / 1024.0 / 1024.0 / 1024.0 / 1024.0
29
+ end
30
+
31
+ def to_z
32
+ Zetta.new @value / 1024.0 / 1024.0 / 1024.0 / 1024.0 / 1024.0 / 1024.0 / 1024.0
33
+ end
34
+
35
+ def to_y
36
+ Yotta.new @value / 1024.0 / 1024.0 / 1024.0 / 1024.0 / 1024.0 / 1024.0 / 1024.0 / 1024.0
37
+ end
18
38
  end
19
- end
39
+ end
@@ -1,6 +1,6 @@
1
1
  module Humanize
2
2
  class Bytes
3
- VERSION = '2.1.0'
3
+ VERSION = '2.2.0'
4
4
 
5
5
  def initialize(value)
6
6
  @value = value.to_f
@@ -17,4 +17,4 @@ module Humanize
17
17
  ("%.#{size}f" % value).to_s
18
18
  end
19
19
  end
20
- end
20
+ end
@@ -0,0 +1,39 @@
1
+ module Humanize
2
+ class Exa < Bytes
3
+ def to_b
4
+ Byte.new @value * 1024 * 1024 * 1024 * 1024 * 1024 * 1024
5
+ end
6
+
7
+ def to_k
8
+ Kilo.new @value * 1024 * 1024 * 1024 * 1024 * 1024
9
+ end
10
+
11
+ def to_m
12
+ Mega.new @value * 1024 * 1024 * 1024 * 1024
13
+ end
14
+
15
+ def to_g
16
+ Giga.new @value * 1024 * 1024 * 1024
17
+ end
18
+
19
+ def to_t
20
+ Tera.new @value * 1024 * 1024
21
+ end
22
+
23
+ def to_p
24
+ Peta.new @value * 1024
25
+ end
26
+
27
+ def to_e
28
+ self
29
+ end
30
+
31
+ def to_z
32
+ Zetta.new @value / 1024.0
33
+ end
34
+
35
+ def to_y
36
+ Yotta.new @value / 1024.0 / 1024.0
37
+ end
38
+ end
39
+ end
@@ -15,5 +15,25 @@ module Humanize
15
15
  def to_g
16
16
  self
17
17
  end
18
+
19
+ def to_t
20
+ Tera.new @value / 1024.0
21
+ end
22
+
23
+ def to_p
24
+ Peta.new @value / 1024.0 / 1024.0
25
+ end
26
+
27
+ def to_e
28
+ Exa.new @value / 1024.0 / 1024.0 / 1024.0
29
+ end
30
+
31
+ def to_z
32
+ Zetta.new @value / 1024.0 / 1024.0 / 1024.0 / 1024.0
33
+ end
34
+
35
+ def to_y
36
+ Yotta.new @value / 1024.0 / 1024.0 / 1024.0 / 1024.0 / 1024.0
37
+ end
18
38
  end
19
39
  end
@@ -15,5 +15,25 @@ module Humanize
15
15
  def to_g
16
16
  Giga.new @value / 1024.0 / 1024
17
17
  end
18
+
19
+ def to_t
20
+ Tera.new @value / 1024.0 / 1024.0 / 1024.0
21
+ end
22
+
23
+ def to_p
24
+ Peta.new @value / 1024.0 / 1024.0 / 1024.0 / 1024.0
25
+ end
26
+
27
+ def to_e
28
+ Exa.new @value / 1024.0 / 1024.0 / 1024.0 / 1024.0 / 1024.0
29
+ end
30
+
31
+ def to_z
32
+ Zetta.new @value / 1024.0 / 1024.0 / 1024.0 / 1024.0 / 1024.0 / 1024.0
33
+ end
34
+
35
+ def to_y
36
+ Yotta.new @value / 1024.0 / 1024.0 / 1024.0 / 1024.0 / 1024.0 / 1024.0 / 1024.0
37
+ end
18
38
  end
19
39
  end
@@ -15,5 +15,25 @@ module Humanize
15
15
  def to_g
16
16
  Giga.new @value / 1024.0
17
17
  end
18
+
19
+ def to_t
20
+ Tera.new @value / 1024.0 / 1024.0
21
+ end
22
+
23
+ def to_p
24
+ Peta.new @value / 1024.0 / 1024.0 / 1024.0
25
+ end
26
+
27
+ def to_e
28
+ Exa.new @value / 1024.0 / 1024.0 / 1024.0 / 1024.0
29
+ end
30
+
31
+ def to_z
32
+ Zetta.new @value / 1024.0 / 1024.0 / 1024.0 / 1024.0 / 1024.0
33
+ end
34
+
35
+ def to_y
36
+ Yotta.new @value / 1024.0 / 1024.0 / 1024.0 / 1024.0 / 1024.0 / 1024.0
37
+ end
18
38
  end
19
39
  end
@@ -0,0 +1,39 @@
1
+ module Humanize
2
+ class Peta < Bytes
3
+ def to_b
4
+ Byte.new @value * 1024 * 1024 * 1024 * 1024 * 1024
5
+ end
6
+
7
+ def to_k
8
+ Kilo.new @value * 1024 * 1024 * 1024 * 1024
9
+ end
10
+
11
+ def to_m
12
+ Mega.new @value * 1024 * 1024 * 1024
13
+ end
14
+
15
+ def to_g
16
+ Giga.new @value * 1024 * 1024
17
+ end
18
+
19
+ def to_t
20
+ Tera.new @value * 1024
21
+ end
22
+
23
+ def to_p
24
+ self
25
+ end
26
+
27
+ def to_e
28
+ Exa.new @value / 1024.0
29
+ end
30
+
31
+ def to_z
32
+ Zetta.new @value / 1024.0 / 1024.0
33
+ end
34
+
35
+ def to_y
36
+ Yotta.new @value / 1024.0 / 1024.0 / 1024.0
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,39 @@
1
+ module Humanize
2
+ class Tera < Bytes
3
+ def to_b
4
+ Byte.new @value * 1024 * 1024 * 1024 * 1024
5
+ end
6
+
7
+ def to_k
8
+ Kilo.new @value * 1024 * 1024 * 1024
9
+ end
10
+
11
+ def to_m
12
+ Mega.new @value * 1024 * 1024
13
+ end
14
+
15
+ def to_g
16
+ Giga.new @value * 1024
17
+ end
18
+
19
+ def to_t
20
+ self
21
+ end
22
+
23
+ def to_p
24
+ Peta.new @value / 1024.0
25
+ end
26
+
27
+ def to_e
28
+ Exa.new @value / 1024.0 / 1024.0
29
+ end
30
+
31
+ def to_z
32
+ Zetta.new @value / 1024.0 / 1024.0 / 1024.0
33
+ end
34
+
35
+ def to_y
36
+ Yotta.new @value / 1024.0 / 1024.0 / 1024.0 / 1024.0
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,39 @@
1
+ module Humanize
2
+ class Yotta < Bytes
3
+ def to_b
4
+ Byte.new @value * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024
5
+ end
6
+
7
+ def to_k
8
+ Kilo.new @value * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024
9
+ end
10
+
11
+ def to_m
12
+ Mega.new @value * 1024 * 1024 * 1024 * 1024 * 1024 * 1024
13
+ end
14
+
15
+ def to_g
16
+ Giga.new @value * 1024 * 1024 * 1024 * 1024 * 1024
17
+ end
18
+
19
+ def to_t
20
+ Tera.new @value * 1024 * 1024 * 1024 * 1024
21
+ end
22
+
23
+ def to_p
24
+ Peta.new @value * 1024 * 1024 * 1024
25
+ end
26
+
27
+ def to_e
28
+ Exa.new @value * 1024 * 1024
29
+ end
30
+
31
+ def to_z
32
+ Zetta.new @value * 1024
33
+ end
34
+
35
+ def to_y
36
+ self
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,39 @@
1
+ module Humanize
2
+ class Zetta < Bytes
3
+ def to_b
4
+ Byte.new @value * 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024
5
+ end
6
+
7
+ def to_k
8
+ Kilo.new @value * 1024 * 1024 * 1024 * 1024 * 1024 * 1024
9
+ end
10
+
11
+ def to_m
12
+ Mega.new @value * 1024 * 1024 * 1024 * 1024 * 1024
13
+ end
14
+
15
+ def to_g
16
+ Giga.new @value * 1024 * 1024 * 1024 * 1024
17
+ end
18
+
19
+ def to_t
20
+ Tera.new @value * 1024 * 1024 * 1024
21
+ end
22
+
23
+ def to_p
24
+ Peta.new @value * 1024 * 1024
25
+ end
26
+
27
+ def to_e
28
+ Exa.new @value * 1024
29
+ end
30
+
31
+ def to_z
32
+ self
33
+ end
34
+
35
+ def to_y
36
+ Yotta.new @value / 1024.0
37
+ end
38
+ end
39
+ end
@@ -48,6 +48,56 @@ describe Humanize::Byte do
48
48
  end
49
49
  end
50
50
 
51
+ context "#to_t" do
52
+ it "should convert to Tera bytes" do
53
+ expect(b.to_t).to be_an_instance_of(Humanize::Tera)
54
+ end
55
+
56
+ it "should convert the value to Tera bytes" do
57
+ expect(b.to_t.value).to eq(0.0019534524180926383)
58
+ end
59
+ end
60
+
61
+ context "#to_p" do
62
+ it "should convert to Peta bytes" do
63
+ expect(b.to_p).to be_an_instance_of(Humanize::Peta)
64
+ end
65
+
66
+ it "should convert the value to Peta bytes" do
67
+ expect(b.to_p.value).to eq(0.000001907668377043592)
68
+ end
69
+ end
70
+
71
+ context "#to_e" do
72
+ it "should convert to Exa bytes" do
73
+ expect(b.to_e).to be_an_instance_of(Humanize::Exa)
74
+ end
75
+
76
+ it "should convert the value to Exa bytes" do
77
+ expect(b.to_e.value).to eq(0.000000001862957399456633)
78
+ end
79
+ end
80
+
81
+ context "#to_z" do
82
+ it "should convert to Zetta bytes" do
83
+ expect(b.to_z).to be_an_instance_of(Humanize::Zetta)
84
+ end
85
+
86
+ it "should convert the value to Zetta bytes" do
87
+ expect(b.to_z.value).to eq(0.000000000001819294335406868)
88
+ end
89
+ end
90
+
91
+ context "#to_y" do
92
+ it "should convert to Yotta bytes" do
93
+ expect(b.to_y).to be_an_instance_of(Humanize::Yotta)
94
+ end
95
+
96
+ it "should convert the value to Yotta bytes" do
97
+ expect(b.to_y.value).to eq(0.0000000000000017766546244207696)
98
+ end
99
+ end
100
+
51
101
  context "#to_s" do
52
102
  context 'without any specification' do
53
103
  it "should return a float with all digits" do
@@ -0,0 +1,121 @@
1
+ require 'spec_helper'
2
+
3
+ describe Humanize::Exa do
4
+ let(:e) { Humanize::Exa.new(205) }
5
+
6
+ context "initialize" do
7
+ it "should convert the number to float" do
8
+ expect(Humanize::Exa.new('3').value).to be_an_instance_of(Float)
9
+ end
10
+ end
11
+
12
+ context "#value" do
13
+ it "should return the value" do
14
+ expect(e.value).to eq(205)
15
+ end
16
+ end
17
+
18
+ context "#to_b" do
19
+ it "should convert to Bytes" do
20
+ expect(e.to_b).to be_an_instance_of(Humanize::Byte)
21
+ end
22
+
23
+ it "should convert the value to Byte" do
24
+ expect(e.to_b.value).to eq(2.3634890844440363e+20)
25
+ end
26
+ end
27
+
28
+ context "#to_k" do
29
+ it "should convert to Kilo bytes" do
30
+ expect(e.to_k).to be_an_instance_of(Humanize::Kilo)
31
+ end
32
+
33
+ it "should convert the value to Kilo bytes" do
34
+ expect(e.to_k.value).to eq(230809480902737920)
35
+ end
36
+ end
37
+
38
+ context "#to_m" do
39
+ it "should convert to Mega bytes" do
40
+ expect(e.to_m).to be_an_instance_of(Humanize::Mega)
41
+ end
42
+
43
+ it "should convert the value to Mega bytes" do
44
+ expect(e.to_m.value).to eq(225399883694080)
45
+ end
46
+ end
47
+
48
+ context "#to_g" do
49
+ it "should convert to Giga bytes" do
50
+ expect(e.to_g).to be_an_instance_of(Humanize::Giga)
51
+ end
52
+
53
+ it "should convert the value to Giga bytes" do
54
+ expect(e.to_g.value).to eq(220117073920)
55
+ end
56
+ end
57
+
58
+ context "#to_t" do
59
+ it "should convert to Tera bytes" do
60
+ expect(e.to_t).to be_an_instance_of(Humanize::Tera)
61
+ end
62
+
63
+ it "should convert the value to Tera bytes" do
64
+ expect(e.to_t.value).to eq(214958080)
65
+ end
66
+ end
67
+
68
+ context "#to_p" do
69
+ it "should convert to Peta bytes" do
70
+ expect(e.to_p).to be_an_instance_of(Humanize::Peta)
71
+ end
72
+
73
+ it "should convert the value to Peta bytes" do
74
+ expect(e.to_p.value).to eq(209920)
75
+ end
76
+ end
77
+
78
+ context "#to_e" do
79
+ it "should return self" do
80
+ expect(e.to_e).to be e
81
+ end
82
+ end
83
+
84
+ context "#to_z" do
85
+ it "should convert to Zetta bytes" do
86
+ expect(e.to_z).to be_an_instance_of(Humanize::Zetta)
87
+ end
88
+
89
+ it "should convert the value to Zetta bytes" do
90
+ expect(e.to_z.value).to eq(0.2001953125)
91
+ end
92
+ end
93
+
94
+ context "#to_y" do
95
+ it "should convert to Yotta bytes" do
96
+ expect(e.to_y).to be_an_instance_of(Humanize::Yotta)
97
+ end
98
+
99
+ it "should convert the value to Yotta bytes" do
100
+ expect(e.to_y.value).to eq(0.00019550323486328125)
101
+ end
102
+ end
103
+
104
+ context "#to_s" do
105
+ context 'without any specification' do
106
+ it "should return a float with all digits" do
107
+ expect(e.to_s).to eq('205')
108
+ end
109
+ end
110
+
111
+ context 'with decimal_digits specified' do
112
+ before :each do
113
+ @e = Humanize::Exa.new 205.534
114
+ end
115
+
116
+ it "should return a float with specified digits" do
117
+ expect(@e.to_s(:decimal_digits => 3)).to eq('205.534')
118
+ end
119
+ end
120
+ end
121
+ end
@@ -48,6 +48,56 @@ describe Humanize::Giga do
48
48
  end
49
49
  end
50
50
 
51
+ context "#to_t" do
52
+ it "should convert to Tera bytes" do
53
+ expect(g.to_t).to be_an_instance_of(Humanize::Tera)
54
+ end
55
+
56
+ it "should convert the value to Tera bytes" do
57
+ expect(g.to_t.value).to eq(0.003173828125)
58
+ end
59
+ end
60
+
61
+ context "#to_p" do
62
+ it "should convert to Peta bytes" do
63
+ expect(g.to_p).to be_an_instance_of(Humanize::Peta)
64
+ end
65
+
66
+ it "should convert the value to Peta bytes" do
67
+ expect(g.to_p.value).to eq(0.0000030994415283203125)
68
+ end
69
+ end
70
+
71
+ context "#to_e" do
72
+ it "should convert to Exa bytes" do
73
+ expect(g.to_e).to be_an_instance_of(Humanize::Exa)
74
+ end
75
+
76
+ it "should convert the value to Exa bytes" do
77
+ expect(g.to_e.value).to eq(0.000000003026798367500305)
78
+ end
79
+ end
80
+
81
+ context "#to_z" do
82
+ it "should convert to Zetta bytes" do
83
+ expect(g.to_z).to be_an_instance_of(Humanize::Zetta)
84
+ end
85
+
86
+ it "should convert the value to Zetta bytes" do
87
+ expect(g.to_z.value).to eq(0.0000000000029558577807620168)
88
+ end
89
+ end
90
+
91
+ context "#to_y" do
92
+ it "should convert to Yotta bytes" do
93
+ expect(g.to_y).to be_an_instance_of(Humanize::Yotta)
94
+ end
95
+
96
+ it "should convert the value to Yotta bytes" do
97
+ expect(g.to_y.value).to eq(0.000000000000002886579864025407)
98
+ end
99
+ end
100
+
51
101
  context "#to_s" do
52
102
  context 'without any specification' do
53
103
  it "should return a float with all digits" do
@@ -48,6 +48,56 @@ describe Humanize::Kilo do
48
48
  end
49
49
  end
50
50
 
51
+ context "#to_t" do
52
+ it "should convert to Tera bytes" do
53
+ expect(k.to_t).to be_an_instance_of(Humanize::Tera)
54
+ end
55
+
56
+ it "should convert the value to Tera bytes" do
57
+ expect(k.to_t.value).to eq(0.000004656612873077393)
58
+ end
59
+ end
60
+
61
+ context "#to_p" do
62
+ it "should convert to Peta bytes" do
63
+ expect(k.to_p).to be_an_instance_of(Humanize::Peta)
64
+ end
65
+
66
+ it "should convert the value to Peta bytes" do
67
+ expect(k.to_p.value).to eq(0.000000004547473508864641)
68
+ end
69
+ end
70
+
71
+ context "#to_e" do
72
+ it "should convert to Exa bytes" do
73
+ expect(k.to_e).to be_an_instance_of(Humanize::Exa)
74
+ end
75
+
76
+ it "should convert the value to Exa bytes" do
77
+ expect(k.to_e.value).to eq(0.000000000004440892098500626)
78
+ end
79
+ end
80
+
81
+ context "#to_z" do
82
+ it "should convert to Zetta bytes" do
83
+ expect(k.to_z).to be_an_instance_of(Humanize::Zetta)
84
+ end
85
+
86
+ it "should convert the value to Zetta bytes" do
87
+ expect(k.to_z.value).to eq(0.000000000000004336808689942018)
88
+ end
89
+ end
90
+
91
+ context "#to_y" do
92
+ it "should convert to Yotta bytes" do
93
+ expect(k.to_y).to be_an_instance_of(Humanize::Yotta)
94
+ end
95
+
96
+ it "should convert the value to Yotta bytes" do
97
+ expect(k.to_y.value).to eq(4.235164736271502e-18)
98
+ end
99
+ end
100
+
51
101
  context "#to_s" do
52
102
  context 'without any specification' do
53
103
  it "should return a float with all digits" do
@@ -48,6 +48,56 @@ describe Humanize::Mega do
48
48
  end
49
49
  end
50
50
 
51
+ context "#to_t" do
52
+ it "should convert to Tera bytes" do
53
+ expect(m.to_t).to be_an_instance_of(Humanize::Tera)
54
+ end
55
+
56
+ it "should convert the value to Tera bytes" do
57
+ expect(m.to_t.value).to eq(0.000004656612873077393)
58
+ end
59
+ end
60
+
61
+ context "#to_p" do
62
+ it "should convert to Peta bytes" do
63
+ expect(m.to_p).to be_an_instance_of(Humanize::Peta)
64
+ end
65
+
66
+ it "should convert the value to Peta bytes" do
67
+ expect(m.to_p.value).to eq(0.000000004547473508864641)
68
+ end
69
+ end
70
+
71
+ context "#to_e" do
72
+ it "should convert to Exa bytes" do
73
+ expect(m.to_e).to be_an_instance_of(Humanize::Exa)
74
+ end
75
+
76
+ it "should convert the value to Exa bytes" do
77
+ expect(m.to_e.value).to eq(0.000000000004440892098500626)
78
+ end
79
+ end
80
+
81
+ context "#to_z" do
82
+ it "should convert to Zetta bytes" do
83
+ expect(m.to_z).to be_an_instance_of(Humanize::Zetta)
84
+ end
85
+
86
+ it "should convert the value to Zetta bytes" do
87
+ expect(m.to_z.value).to eq(0.000000000000004336808689942018)
88
+ end
89
+ end
90
+
91
+ context "#to_y" do
92
+ it "should convert to Yotta bytes" do
93
+ expect(m.to_y).to be_an_instance_of(Humanize::Yotta)
94
+ end
95
+
96
+ it "should convert the value to Yotta bytes" do
97
+ expect(m.to_y.value).to eq(4.235164736271502e-18)
98
+ end
99
+ end
100
+
51
101
  context "#to_s" do
52
102
  context 'without any specification' do
53
103
  it "should return a float with all digits" do
@@ -0,0 +1,121 @@
1
+ require 'spec_helper'
2
+
3
+ describe Humanize::Peta do
4
+ let(:p) { Humanize::Peta.new(125) }
5
+
6
+ context "initialize" do
7
+ it "should convert the number to float" do
8
+ expect(Humanize::Peta.new('3').value).to be_an_instance_of(Float)
9
+ end
10
+ end
11
+
12
+ context "#value" do
13
+ it "should return the value" do
14
+ expect(p.value).to eq(125)
15
+ end
16
+ end
17
+
18
+ context "#to_b" do
19
+ it "should convert to Bytes" do
20
+ expect(p.to_b).to be_an_instance_of(Humanize::Byte)
21
+ end
22
+
23
+ it "should convert the value to Byte" do
24
+ expect(p.to_b.value).to eq(140737488355328000)
25
+ end
26
+ end
27
+
28
+ context "#to_k" do
29
+ it "should convert to Kilo bytes" do
30
+ expect(p.to_k).to be_an_instance_of(Humanize::Kilo)
31
+ end
32
+
33
+ it "should convert the value to Kilo bytes" do
34
+ expect(p.to_k.value).to eq(137438953472000)
35
+ end
36
+ end
37
+
38
+ context "#to_m" do
39
+ it "should convert to Mega bytes" do
40
+ expect(p.to_m).to be_an_instance_of(Humanize::Mega)
41
+ end
42
+
43
+ it "should convert the value to Mega bytes" do
44
+ expect(p.to_m.value).to eq(134217728000)
45
+ end
46
+ end
47
+
48
+ context "#to_g" do
49
+ it "should convert to Giga bytes" do
50
+ expect(p.to_g).to be_an_instance_of(Humanize::Giga)
51
+ end
52
+
53
+ it "should convert the value to Giga bytes" do
54
+ expect(p.to_g.value).to eq(131072000)
55
+ end
56
+ end
57
+
58
+ context "#to_t" do
59
+ it "should convert to Tera bytes" do
60
+ expect(p.to_t).to be_an_instance_of(Humanize::Tera)
61
+ end
62
+
63
+ it "should convert the value to Tera bytes" do
64
+ expect(p.to_t.value).to eq(128000)
65
+ end
66
+ end
67
+
68
+ context "#to_p" do
69
+ it "should return self" do
70
+ expect(p.to_p).to be p
71
+ end
72
+ end
73
+
74
+ context "#to_e" do
75
+ it "should convert to Exa bytes" do
76
+ expect(p.to_e).to be_an_instance_of(Humanize::Exa)
77
+ end
78
+
79
+ it "should convert the value to Exa bytes" do
80
+ expect(p.to_e.value).to eq(0.1220703125)
81
+ end
82
+ end
83
+
84
+ context "#to_z" do
85
+ it "should convert to Zetta bytes" do
86
+ expect(p.to_z).to be_an_instance_of(Humanize::Zetta)
87
+ end
88
+
89
+ it "should convert the value to Zetta bytes" do
90
+ expect(p.to_z.value).to eq(0.00011920928955078125)
91
+ end
92
+ end
93
+
94
+ context "#to_y" do
95
+ it "should convert to Yotta bytes" do
96
+ expect(p.to_y).to be_an_instance_of(Humanize::Yotta)
97
+ end
98
+
99
+ it "should convert the value to Yotta bytes" do
100
+ expect(p.to_y.value).to eq(0.00000011641532182693481)
101
+ end
102
+ end
103
+
104
+ context "#to_s" do
105
+ context 'without any specification' do
106
+ it "should return a float with all digits" do
107
+ expect(p.to_s).to eq('125')
108
+ end
109
+ end
110
+
111
+ context 'with decimal_digits specified' do
112
+ before :each do
113
+ @p = Humanize::Peta.new 125.532
114
+ end
115
+
116
+ it "should return a float with specified digits" do
117
+ expect(@p.to_s(:decimal_digits => 3)).to eq('125.532')
118
+ end
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,121 @@
1
+ require 'spec_helper'
2
+
3
+ describe Humanize::Tera do
4
+ let(:t) { Humanize::Tera.new(100) }
5
+
6
+ context "initialize" do
7
+ it "should convert the number to float" do
8
+ expect(Humanize::Tera.new('3').value).to be_an_instance_of(Float)
9
+ end
10
+ end
11
+
12
+ context "#value" do
13
+ it "should return the value" do
14
+ expect(t.value).to eq(100)
15
+ end
16
+ end
17
+
18
+ context "#to_b" do
19
+ it "should convert to Bytes" do
20
+ expect(t.to_b).to be_an_instance_of(Humanize::Byte)
21
+ end
22
+
23
+ it "should convert the value to Byte" do
24
+ expect(t.to_b.value).to eq(109951162777600)
25
+ end
26
+ end
27
+
28
+ context "#to_k" do
29
+ it "should convert to Kilo bytes" do
30
+ expect(t.to_k).to be_an_instance_of(Humanize::Kilo)
31
+ end
32
+
33
+ it "should convert the value to Kilo bytes" do
34
+ expect(t.to_k.value).to eq(107374182400)
35
+ end
36
+ end
37
+
38
+ context "#to_m" do
39
+ it "should convert to Mega bytes" do
40
+ expect(t.to_m).to be_an_instance_of(Humanize::Mega)
41
+ end
42
+
43
+ it "should convert the value to Mega bytes" do
44
+ expect(t.to_m.value).to eq(104857600)
45
+ end
46
+ end
47
+
48
+ context "#to_g" do
49
+ it "should convert to Giga bytes" do
50
+ expect(t.to_g).to be_an_instance_of(Humanize::Giga)
51
+ end
52
+
53
+ it "should convert the value to Giga bytes" do
54
+ expect(t.to_g.value).to eq(102400)
55
+ end
56
+ end
57
+
58
+ context "#to_t" do
59
+ it "should return self" do
60
+ expect(t.to_t).to be t
61
+ end
62
+ end
63
+
64
+ context "#to_p" do
65
+ it "should convert to Peta bytes" do
66
+ expect(t.to_p).to be_an_instance_of(Humanize::Peta)
67
+ end
68
+
69
+ it "should convert the value to Peta bytes" do
70
+ expect(t.to_p.value).to eq(0.09765625)
71
+ end
72
+ end
73
+
74
+ context "#to_e" do
75
+ it "should convert to Exa bytes" do
76
+ expect(t.to_e).to be_an_instance_of(Humanize::Exa)
77
+ end
78
+
79
+ it "should convert the value to Exa bytes" do
80
+ expect(t.to_e.value).to eq(0.000095367431640625)
81
+ end
82
+ end
83
+
84
+ context "#to_z" do
85
+ it "should convert to Zetta bytes" do
86
+ expect(t.to_z).to be_an_instance_of(Humanize::Zetta)
87
+ end
88
+
89
+ it "should convert the value to Zetta bytes" do
90
+ expect(t.to_z.value).to eq(0.00000009313225746154785)
91
+ end
92
+ end
93
+
94
+ context "#to_y" do
95
+ it "should convert to Yotta bytes" do
96
+ expect(t.to_y).to be_an_instance_of(Humanize::Yotta)
97
+ end
98
+
99
+ it "should convert the value to Yotta bytes" do
100
+ expect(t.to_y.value).to eq(0.00000000009094947017729282)
101
+ end
102
+ end
103
+
104
+ context "#to_s" do
105
+ context 'without any specification' do
106
+ it "should return a float with all digits" do
107
+ expect(t.to_s).to eq('100')
108
+ end
109
+ end
110
+
111
+ context 'with decimal_digits specified' do
112
+ before :each do
113
+ @t = Humanize::Tera.new 100.05
114
+ end
115
+
116
+ it "should return a float with specified digits" do
117
+ expect(@t.to_s(:decimal_digits => 2)).to eq('100.05')
118
+ end
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,121 @@
1
+ require 'spec_helper'
2
+
3
+ describe Humanize::Yotta do
4
+ let(:y) { Humanize::Yotta.new(7) }
5
+
6
+ context "initialize" do
7
+ it "should convert the number to float" do
8
+ expect(Humanize::Yotta.new('3').value).to be_an_instance_of(Float)
9
+ end
10
+ end
11
+
12
+ context "#value" do
13
+ it "should return the value" do
14
+ expect(y.value).to eq(7)
15
+ end
16
+ end
17
+
18
+ context "#to_b" do
19
+ it "should convert to Bytes" do
20
+ expect(y.to_b).to be_an_instance_of(Humanize::Byte)
21
+ end
22
+
23
+ it "should convert the value to Byte" do
24
+ expect(y.to_b.value).to eq(8.462480737302404e+24)
25
+ end
26
+ end
27
+
28
+ context "#to_k" do
29
+ it "should convert to Kilo bytes" do
30
+ expect(y.to_k).to be_an_instance_of(Humanize::Kilo)
31
+ end
32
+
33
+ it "should convert the value to Kilo bytes" do
34
+ expect(y.to_k.value).to eq(8.264141345021879e+21)
35
+ end
36
+ end
37
+
38
+ context "#to_m" do
39
+ it "should convert to Mega bytes" do
40
+ expect(y.to_m).to be_an_instance_of(Humanize::Mega)
41
+ end
42
+
43
+ it "should convert the value to Mega bytes" do
44
+ expect(y.to_m.value).to eq(8.070450532247929e+18)
45
+ end
46
+ end
47
+
48
+ context "#to_g" do
49
+ it "should convert to Giga bytes" do
50
+ expect(y.to_g).to be_an_instance_of(Humanize::Giga)
51
+ end
52
+
53
+ it "should convert the value to Giga bytes" do
54
+ expect(y.to_g.value).to eq(7.881299347898368e+15)
55
+ end
56
+ end
57
+
58
+ context "#to_t" do
59
+ it "should convert to Tera bytes" do
60
+ expect(y.to_t).to be_an_instance_of(Humanize::Tera)
61
+ end
62
+
63
+ it "should convert the value to Tera bytes" do
64
+ expect(y.to_t.value).to eq(7696581394432)
65
+ end
66
+ end
67
+
68
+ context "#to_p" do
69
+ it "should convert to Peta bytes" do
70
+ expect(y.to_p).to be_an_instance_of(Humanize::Peta)
71
+ end
72
+
73
+ it "should convert the value to Peta bytes" do
74
+ expect(y.to_p.value).to eq(7516192768)
75
+ end
76
+ end
77
+
78
+ context "#to_e" do
79
+ it "should convert to Exa bytes" do
80
+ expect(y.to_e).to be_an_instance_of(Humanize::Exa)
81
+ end
82
+
83
+ it "should convert the value to Exa bytes" do
84
+ expect(y.to_e.value).to eq(7340032)
85
+ end
86
+ end
87
+
88
+ context "#to_z" do
89
+ it "should convert to Zetta bytes" do
90
+ expect(y.to_z).to be_an_instance_of(Humanize::Zetta)
91
+ end
92
+
93
+ it "should convert the value to Zetta bytes" do
94
+ expect(y.to_z.value).to eq(7168)
95
+ end
96
+ end
97
+
98
+ context "#to_y" do
99
+ it "should return self" do
100
+ expect(y.to_y).to be y
101
+ end
102
+ end
103
+
104
+ context "#to_s" do
105
+ context 'without any specification' do
106
+ it "should return a float with all digits" do
107
+ expect(y.to_s).to eq('7')
108
+ end
109
+ end
110
+
111
+ context 'with decimal_digits specified' do
112
+ before :each do
113
+ @y = Humanize::Yotta.new 7.13
114
+ end
115
+
116
+ it "should return a float with specified digits" do
117
+ expect(@y.to_s(:decimal_digits => 2)).to eq('7.13')
118
+ end
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,121 @@
1
+ require 'spec_helper'
2
+
3
+ describe Humanize::Zetta do
4
+ let(:z) { Humanize::Zetta.new(35) }
5
+
6
+ context "initialize" do
7
+ it "should convert the number to float" do
8
+ expect(Humanize::Zetta.new('3').value).to be_an_instance_of(Float)
9
+ end
10
+ end
11
+
12
+ context "#value" do
13
+ it "should return the value" do
14
+ expect(z.value).to eq(35)
15
+ end
16
+ end
17
+
18
+ context "#to_b" do
19
+ it "should convert to Bytes" do
20
+ expect(z.to_b).to be_an_instance_of(Humanize::Byte)
21
+ end
22
+
23
+ it "should convert the value to Byte" do
24
+ expect(z.to_b.value).to eq(4.1320706725109396e+22)
25
+ end
26
+ end
27
+
28
+ context "#to_k" do
29
+ it "should convert to Kilo bytes" do
30
+ expect(z.to_k).to be_an_instance_of(Humanize::Kilo)
31
+ end
32
+
33
+ it "should convert the value to Kilo bytes" do
34
+ expect(z.to_k.value).to eq(4.0352252661239644e+19)
35
+ end
36
+ end
37
+
38
+ context "#to_m" do
39
+ it "should convert to Mega bytes" do
40
+ expect(z.to_m).to be_an_instance_of(Humanize::Mega)
41
+ end
42
+
43
+ it "should convert the value to Mega bytes" do
44
+ expect(z.to_m.value).to eq(3.940649673949184e+16)
45
+ end
46
+ end
47
+
48
+ context "#to_g" do
49
+ it "should convert to Giga bytes" do
50
+ expect(z.to_g).to be_an_instance_of(Humanize::Giga)
51
+ end
52
+
53
+ it "should convert the value to Giga bytes" do
54
+ expect(z.to_g.value).to eq(38482906972160)
55
+ end
56
+ end
57
+
58
+ context "#to_t" do
59
+ it "should convert to Tera bytes" do
60
+ expect(z.to_t).to be_an_instance_of(Humanize::Tera)
61
+ end
62
+
63
+ it "should convert the value to Tera bytes" do
64
+ expect(z.to_t.value).to eq(37580963840)
65
+ end
66
+ end
67
+
68
+ context "#to_p" do
69
+ it "should convert to Peta bytes" do
70
+ expect(z.to_p).to be_an_instance_of(Humanize::Peta)
71
+ end
72
+
73
+ it "should convert the value to Peta bytes" do
74
+ expect(z.to_p.value).to eq(36700160)
75
+ end
76
+ end
77
+
78
+ context "#to_e" do
79
+ it "should convert to Exa bytes" do
80
+ expect(z.to_e).to be_an_instance_of(Humanize::Exa)
81
+ end
82
+
83
+ it "should convert the value to Exa bytes" do
84
+ expect(z.to_e.value).to eq(35840)
85
+ end
86
+ end
87
+
88
+ context "#to_z" do
89
+ it "should return self" do
90
+ expect(z.to_z).to be z
91
+ end
92
+ end
93
+
94
+ context "#to_y" do
95
+ it "should convert to Yotta bytes" do
96
+ expect(z.to_y).to be_an_instance_of(Humanize::Yotta)
97
+ end
98
+
99
+ it "should convert the value to Yotta bytes" do
100
+ expect(z.to_y.value).to eq(0.0341796875)
101
+ end
102
+ end
103
+
104
+ context "#to_s" do
105
+ context 'without any specification' do
106
+ it "should return a float with all digits" do
107
+ expect(z.to_s).to eq('35')
108
+ end
109
+ end
110
+
111
+ context 'with decimal_digits specified' do
112
+ before :each do
113
+ @z = Humanize::Zetta.new 35.15
114
+ end
115
+
116
+ it "should return a float with specified digits" do
117
+ expect(@z.to_s(:decimal_digits => 2)).to eq('35.15')
118
+ end
119
+ end
120
+ end
121
+ end
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.1.0
4
+ version: 2.2.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-09-13 00:00:00.000000000 Z
11
+ date: 2015-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -71,13 +71,23 @@ files:
71
71
  - lib/humanize-bytes.rb
72
72
  - lib/humanize/byte.rb
73
73
  - lib/humanize/bytes.rb
74
+ - lib/humanize/exa.rb
74
75
  - lib/humanize/giga.rb
75
76
  - lib/humanize/kilo.rb
76
77
  - lib/humanize/mega.rb
78
+ - lib/humanize/peta.rb
79
+ - lib/humanize/tera.rb
80
+ - lib/humanize/yotta.rb
81
+ - lib/humanize/zetta.rb
77
82
  - spec/humanize/byte_spec.rb
83
+ - spec/humanize/exa_spec.rb
78
84
  - spec/humanize/giga_spec.rb
79
85
  - spec/humanize/kilo_spec.rb
80
86
  - spec/humanize/mega_spec.rb
87
+ - spec/humanize/peta_spec.rb
88
+ - spec/humanize/tera_spec.rb
89
+ - spec/humanize/yotta_spec.rb
90
+ - spec/humanize/zetta_spec.rb
81
91
  - spec/spec_helper.rb
82
92
  homepage:
83
93
  licenses:
@@ -99,13 +109,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
109
  version: '0'
100
110
  requirements: []
101
111
  rubyforge_project:
102
- rubygems_version: 2.2.2
112
+ rubygems_version: 2.4.5.1
103
113
  signing_key:
104
114
  specification_version: 4
105
- summary: Convert Byte, Kbyte, MByte, Gbyte into each other
115
+ summary: Convert Byte, KByte, MByte, GByte, TByte, PByte, EByte, ZByte and YByte into
116
+ each other
106
117
  test_files:
107
118
  - spec/humanize/byte_spec.rb
119
+ - spec/humanize/exa_spec.rb
108
120
  - spec/humanize/giga_spec.rb
109
121
  - spec/humanize/kilo_spec.rb
110
122
  - spec/humanize/mega_spec.rb
123
+ - spec/humanize/peta_spec.rb
124
+ - spec/humanize/tera_spec.rb
125
+ - spec/humanize/yotta_spec.rb
126
+ - spec/humanize/zetta_spec.rb
111
127
  - spec/spec_helper.rb