humanize-bytes 0.1.0 → 1.0.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.
- data/.rvmrc +1 -1
- data/lib/humanize-bytes.rb +2 -6
- data/lib/humanize-bytes/byte.rb +4 -4
- data/lib/humanize-bytes/gbyte.rb +4 -4
- data/lib/humanize-bytes/kbyte.rb +4 -4
- data/lib/humanize-bytes/mbyte.rb +4 -4
- data/lib/humanize-bytes/version.rb +1 -1
- data/spec/humanize_bytes/byte_spec.rb +17 -8
- data/spec/humanize_bytes/gbyte_spec.rb +17 -8
- data/spec/humanize_bytes/kbyte_spec.rb +17 -8
- data/spec/humanize_bytes/mbyte_spec.rb +17 -8
- data/spec/spec_helper.rb +3 -1
- metadata +23 -7
data/.rvmrc
CHANGED
@@ -1 +1 @@
|
|
1
|
-
rvm use 1.9.3-
|
1
|
+
rvm use 1.9.3-p194@humanize_bytes --create
|
data/lib/humanize-bytes.rb
CHANGED
@@ -7,16 +7,12 @@ module Humanize
|
|
7
7
|
autoload :Mega, 'humanize-bytes/mbyte'
|
8
8
|
autoload :Giga, 'humanize-bytes/gbyte'
|
9
9
|
|
10
|
-
def self.initialize(value, unit =
|
11
|
-
case unit
|
10
|
+
def self.initialize(value, unit = 'b')
|
11
|
+
case unit.to_s
|
12
12
|
when 'b' then Humanize::Bytes::Byte.new(value)
|
13
13
|
when 'k' then Humanize::Bytes::Kilo.new(value)
|
14
14
|
when 'm' then Humanize::Bytes::Mega.new(value)
|
15
15
|
when 'g' then Humanize::Bytes::Giga.new(value)
|
16
|
-
when :b then Humanize::Bytes::Byte.new(value)
|
17
|
-
when :k then Humanize::Bytes::Kilo.new(value)
|
18
|
-
when :m then Humanize::Bytes::Mega.new(value)
|
19
|
-
when :g then Humanize::Bytes::Giga.new(value)
|
20
16
|
else nil
|
21
17
|
end
|
22
18
|
end
|
data/lib/humanize-bytes/byte.rb
CHANGED
@@ -10,19 +10,19 @@ module Humanize
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def to_b
|
13
|
-
|
13
|
+
self
|
14
14
|
end
|
15
15
|
|
16
16
|
def to_k
|
17
|
-
@value / 1024.0
|
17
|
+
Kilo.new @value / 1024.0
|
18
18
|
end
|
19
19
|
|
20
20
|
def to_m
|
21
|
-
@value / 1024.0 / 1024
|
21
|
+
Mega.new @value / 1024.0 / 1024
|
22
22
|
end
|
23
23
|
|
24
24
|
def to_g
|
25
|
-
@value / 1024.0 / 1024 / 1024
|
25
|
+
Giga.new @value / 1024.0 / 1024 / 1024
|
26
26
|
end
|
27
27
|
|
28
28
|
def to_s
|
data/lib/humanize-bytes/gbyte.rb
CHANGED
@@ -10,19 +10,19 @@ module Humanize
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def to_b
|
13
|
-
@value * 1024 * 1024 * 1024
|
13
|
+
Byte.new @value * 1024 * 1024 * 1024
|
14
14
|
end
|
15
15
|
|
16
16
|
def to_k
|
17
|
-
@value * 1024 * 1024
|
17
|
+
Kilo.new @value * 1024 * 1024
|
18
18
|
end
|
19
19
|
|
20
20
|
def to_m
|
21
|
-
@value * 1024
|
21
|
+
Mega.new @value * 1024
|
22
22
|
end
|
23
23
|
|
24
24
|
def to_g
|
25
|
-
|
25
|
+
self
|
26
26
|
end
|
27
27
|
|
28
28
|
def to_s
|
data/lib/humanize-bytes/kbyte.rb
CHANGED
@@ -10,19 +10,19 @@ module Humanize
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def to_b
|
13
|
-
@value * 1024
|
13
|
+
Byte.new @value * 1024
|
14
14
|
end
|
15
15
|
|
16
16
|
def to_k
|
17
|
-
|
17
|
+
self
|
18
18
|
end
|
19
19
|
|
20
20
|
def to_m
|
21
|
-
@value / 1024.0
|
21
|
+
Mega.new @value / 1024.0
|
22
22
|
end
|
23
23
|
|
24
24
|
def to_g
|
25
|
-
@value / 1024.0 / 1024
|
25
|
+
Giga.new @value / 1024.0 / 1024
|
26
26
|
end
|
27
27
|
|
28
28
|
def to_s
|
data/lib/humanize-bytes/mbyte.rb
CHANGED
@@ -10,19 +10,19 @@ module Humanize
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def to_b
|
13
|
-
@value * 1024 * 1024
|
13
|
+
Byte.new @value * 1024 * 1024
|
14
14
|
end
|
15
15
|
|
16
16
|
def to_k
|
17
|
-
@value * 1024
|
17
|
+
Kilo.new @value * 1024
|
18
18
|
end
|
19
19
|
|
20
20
|
def to_m
|
21
|
-
|
21
|
+
self
|
22
22
|
end
|
23
23
|
|
24
24
|
def to_g
|
25
|
-
@value / 1024.0
|
25
|
+
Giga.new @value / 1024.0
|
26
26
|
end
|
27
27
|
|
28
28
|
def to_s
|
@@ -10,26 +10,35 @@ describe Humanize::Bytes::Byte do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
context "#to_b" do
|
13
|
-
it "should return
|
14
|
-
b.to_b.should
|
13
|
+
it "should return return self" do
|
14
|
+
b.to_b.should be b
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
context "#to_k" do
|
19
|
-
it "should convert
|
20
|
-
b.to_k.should
|
19
|
+
it "should convert to Kilo bytes" do
|
20
|
+
b.to_k.class.should be Kilo
|
21
|
+
end
|
22
|
+
it "should convert the value to Kilo bytes" do
|
23
|
+
b.to_k.value.should == 2097503.5625
|
21
24
|
end
|
22
25
|
end
|
23
26
|
|
24
27
|
context "#to_m" do
|
25
|
-
it "should convert
|
26
|
-
b.to_m.should
|
28
|
+
it "should convert to Mega bytes" do
|
29
|
+
b.to_m.class.should be Mega
|
30
|
+
end
|
31
|
+
it "should convert the value to Mega bytes" do
|
32
|
+
b.to_m.value.should == 2048.3433227539062
|
27
33
|
end
|
28
34
|
end
|
29
35
|
|
30
36
|
context "#to_g" do
|
31
|
-
it "should convert
|
32
|
-
b.to_g.should
|
37
|
+
it "should convert to Giga bytes" do
|
38
|
+
b.to_g.class.should be Giga
|
39
|
+
end
|
40
|
+
it "should convert the value to Giga bytes" do
|
41
|
+
b.to_g.value.should == 2.0003352761268616
|
33
42
|
end
|
34
43
|
end
|
35
44
|
|
@@ -10,26 +10,35 @@ describe Humanize::Bytes::Giga do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
context "#to_b" do
|
13
|
-
it "should convert
|
14
|
-
g.to_b.should
|
13
|
+
it "should convert to Bytes" do
|
14
|
+
g.to_b.class.should be Byte
|
15
|
+
end
|
16
|
+
it "should convert the value to Byte" do
|
17
|
+
g.to_b.value.should == 3489660928
|
15
18
|
end
|
16
19
|
end
|
17
20
|
|
18
21
|
context "#to_k" do
|
19
|
-
it "should convert
|
20
|
-
g.to_k.should
|
22
|
+
it "should convert to Kilo bytes" do
|
23
|
+
g.to_k.class.should be Kilo
|
24
|
+
end
|
25
|
+
it "should convert the value to Kilo bytes" do
|
26
|
+
g.to_k.value.should == 3407872
|
21
27
|
end
|
22
28
|
end
|
23
29
|
|
24
30
|
context "#to_m" do
|
25
|
-
it "should convert
|
26
|
-
g.to_m.should
|
31
|
+
it "should convert to Mega bytes" do
|
32
|
+
g.to_m.class.should be Mega
|
33
|
+
end
|
34
|
+
it "should convert the value to Mega bytes" do
|
35
|
+
g.to_m.value.should == 3328
|
27
36
|
end
|
28
37
|
end
|
29
38
|
|
30
39
|
context "#to_g" do
|
31
|
-
it "should return
|
32
|
-
g.to_g.should
|
40
|
+
it "should return self" do
|
41
|
+
g.to_g.should be g
|
33
42
|
end
|
34
43
|
end
|
35
44
|
|
@@ -10,26 +10,35 @@ describe Humanize::Bytes::Kilo do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
context "#to_b" do
|
13
|
-
it "should convert
|
14
|
-
k.to_b.should
|
13
|
+
it "should convert to Byte" do
|
14
|
+
k.to_b.class.should be Byte
|
15
|
+
end
|
16
|
+
it "should convert the value to Bytes" do
|
17
|
+
k.to_b.value.should == 5120000
|
15
18
|
end
|
16
19
|
end
|
17
20
|
|
18
21
|
context "#to_k" do
|
19
|
-
it "should return
|
20
|
-
k.to_k.should
|
22
|
+
it "should return self" do
|
23
|
+
k.to_k.should be k
|
21
24
|
end
|
22
25
|
end
|
23
26
|
|
24
27
|
context "#to_m" do
|
25
|
-
it "should convert
|
26
|
-
k.to_m.should
|
28
|
+
it "should convert to Mega bytes" do
|
29
|
+
k.to_m.class.should be Mega
|
30
|
+
end
|
31
|
+
it "should convert the value to Mega bytes" do
|
32
|
+
k.to_m.value.should == 4.8828125
|
27
33
|
end
|
28
34
|
end
|
29
35
|
|
30
36
|
context "#to_g" do
|
31
|
-
it "should convert
|
32
|
-
|
37
|
+
it "should convert to Giga bytes" do
|
38
|
+
k.to_g.class.should be Giga
|
39
|
+
end
|
40
|
+
it "should convert the value to Giga bytes" do
|
41
|
+
k.to_g.value.should == 0.00476837158203125
|
33
42
|
end
|
34
43
|
end
|
35
44
|
|
@@ -10,26 +10,35 @@ describe Humanize::Bytes::Mega do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
context "#to_b" do
|
13
|
-
it "should convert
|
14
|
-
m.to_b.should
|
13
|
+
it "should convert to Byte" do
|
14
|
+
m.to_b.class.should be Byte
|
15
|
+
end
|
16
|
+
it "should convert the value to Bytes" do
|
17
|
+
m.to_b.value.should == 5120000
|
15
18
|
end
|
16
19
|
end
|
17
20
|
|
18
21
|
context "#to_k" do
|
19
|
-
it "should convert
|
20
|
-
m.to_k.should
|
22
|
+
it "should convert to Kilo bytes" do
|
23
|
+
m.to_k.class.should be Kilo
|
24
|
+
end
|
25
|
+
it "should convert the value to Kilo bytes" do
|
26
|
+
m.to_k.value.should == 5000
|
21
27
|
end
|
22
28
|
end
|
23
29
|
|
24
30
|
context "#to_m" do
|
25
|
-
it "should return
|
26
|
-
m.to_m.should
|
31
|
+
it "should return self" do
|
32
|
+
m.to_m.should be m
|
27
33
|
end
|
28
34
|
end
|
29
35
|
|
30
36
|
context "#to_g" do
|
31
|
-
it "should convert
|
32
|
-
|
37
|
+
it "should convert to Giga bytes" do
|
38
|
+
m.to_g.class.should be Giga
|
39
|
+
end
|
40
|
+
it "should convert the value to Giga bytes" do
|
41
|
+
m.to_g.value.should == 0.00476837158203125
|
33
42
|
end
|
34
43
|
end
|
35
44
|
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: humanize-bytes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-09-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: rspec
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ! '>='
|
@@ -32,7 +37,12 @@ dependencies:
|
|
32
37
|
version: 2.0.0
|
33
38
|
type: :development
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.0.0
|
36
46
|
description: Convert Byte, Kbyte, MByte, Gbyte into each other
|
37
47
|
email: plribeiro3000@gmail.com
|
38
48
|
executables: []
|
@@ -71,15 +81,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
71
81
|
- - ! '>='
|
72
82
|
- !ruby/object:Gem::Version
|
73
83
|
version: '0'
|
84
|
+
segments:
|
85
|
+
- 0
|
86
|
+
hash: 2054005163981464363
|
74
87
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
88
|
none: false
|
76
89
|
requirements:
|
77
90
|
- - ! '>='
|
78
91
|
- !ruby/object:Gem::Version
|
79
92
|
version: '0'
|
93
|
+
segments:
|
94
|
+
- 0
|
95
|
+
hash: 2054005163981464363
|
80
96
|
requirements: []
|
81
97
|
rubyforge_project:
|
82
|
-
rubygems_version: 1.8.
|
98
|
+
rubygems_version: 1.8.24
|
83
99
|
signing_key:
|
84
100
|
specification_version: 3
|
85
101
|
summary: Humanize bytes Gem
|