humanize-bytes 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +12 -3
- data/Rakefile +6 -0
- data/lib/humanize-bytes/byte.rb +4 -0
- data/lib/humanize-bytes/gbyte.rb +4 -0
- data/lib/humanize-bytes/kbyte.rb +4 -0
- data/lib/humanize-bytes/mbyte.rb +4 -0
- data/lib/humanize-bytes/version.rb +1 -1
- data/spec/humanize_bytes/byte_spec.rb +6 -0
- data/spec/humanize_bytes/gbyte_spec.rb +6 -0
- data/spec/humanize_bytes/kbyte_spec.rb +6 -0
- data/spec/humanize_bytes/mbyte_spec.rb +6 -0
- data/spec/humanize_bytes_spec.rb +4 -4
- metadata +6 -6
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
# Humanize::Bytes
|
1
|
+
# Humanize::Bytes [![Build Status](https://secure.travis-ci.org/plribeiro3000/humanize-bytes.png)](http://travis-ci.org/plribeiro3000/humanize-bytes)
|
2
2
|
|
3
|
-
|
3
|
+
Convert Byte, Kbyte, MByte, Gbyte into each other easy as to_b.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -18,7 +18,16 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
Initialize the New Object with
|
22
|
+
Humanize::Bytes.initialize(1024)
|
23
|
+
|
24
|
+
The initialization process accept a second argument which is the unit. Available units are: b, k, m, g
|
25
|
+
|
26
|
+
Then call on of the methods: to_b, to_k, to_m, to_g.
|
27
|
+
|
28
|
+
## Note
|
29
|
+
|
30
|
+
The available methods are different depending on the initialization.
|
22
31
|
|
23
32
|
## Contributing
|
24
33
|
|
data/Rakefile
CHANGED
data/lib/humanize-bytes/byte.rb
CHANGED
data/lib/humanize-bytes/gbyte.rb
CHANGED
data/lib/humanize-bytes/kbyte.rb
CHANGED
data/lib/humanize-bytes/mbyte.rb
CHANGED
@@ -9,6 +9,12 @@ describe Humanize::Bytes::Byte do
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
+
context "#to_b" do
|
13
|
+
it "should return the value" do
|
14
|
+
b.to_b.should == 2147843648
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
12
18
|
context "#to_k" do
|
13
19
|
it "should convert the value to kilo bytes" do
|
14
20
|
b.to_k.should == 2097503.5625
|
@@ -27,6 +27,12 @@ describe Humanize::Bytes::Giga do
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
+
context "#to_g" do
|
31
|
+
it "should return the value" do
|
32
|
+
g.to_g.should == 3.25
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
30
36
|
context "#to_s" do
|
31
37
|
context "when value is a decimal" do
|
32
38
|
it "should print a humanized version of the value" do
|
@@ -15,6 +15,12 @@ describe Humanize::Bytes::Kilo do
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
+
context "#to_k" do
|
19
|
+
it "should return the value" do
|
20
|
+
k.to_k.should == 5000
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
18
24
|
context "#to_m" do
|
19
25
|
it "should convert the value to mega bytes" do
|
20
26
|
k.to_m.should == 4.8828125
|
@@ -21,6 +21,12 @@ describe Humanize::Bytes::Mega do
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
+
context "#to_m" do
|
25
|
+
it "should return the value" do
|
26
|
+
m.to_m.should == 4.8828125
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
24
30
|
context "#to_g" do
|
25
31
|
it "should convert the value to giga bytes" do
|
26
32
|
Humanize::Bytes::Mega.new(1000).to_g.should == 0.9765625
|
data/spec/humanize_bytes_spec.rb
CHANGED
@@ -4,25 +4,25 @@ describe Humanize::Bytes do
|
|
4
4
|
describe "#initialize" do
|
5
5
|
context "when no unit is specified" do
|
6
6
|
it "should return a new Byte instance" do
|
7
|
-
Humanize::Bytes.initialize(
|
7
|
+
Humanize::Bytes.initialize(1024).should be_instance_of(Humanize::Bytes::Byte)
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
11
|
context "when kilo is specfied as unit" do
|
12
12
|
it "should return a new Kilo instance" do
|
13
|
-
Humanize::Bytes.initialize(
|
13
|
+
Humanize::Bytes.initialize(1024, 'k').should be_instance_of(Humanize::Bytes::Kilo)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
17
|
context "when mega is specfied as unit" do
|
18
18
|
it "should return a new Mega instance" do
|
19
|
-
Humanize::Bytes.initialize(
|
19
|
+
Humanize::Bytes.initialize(1024, 'm').should be_instance_of(Humanize::Bytes::Mega)
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
context "when giga is specfied as unit" do
|
24
24
|
it "should return a new Giga instance" do
|
25
|
-
Humanize::Bytes.initialize(
|
25
|
+
Humanize::Bytes.initialize(1024, 'g').should be_instance_of(Humanize::Bytes::Giga)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
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: 0.0.
|
4
|
+
version: 0.0.2
|
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-04-
|
12
|
+
date: 2012-04-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement: &
|
16
|
+
requirement: &15077160 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *15077160
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &15092840 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: 2.0.0
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *15092840
|
36
36
|
description: Convert Byte, Kbyte, MByte, Gbyte into each other
|
37
37
|
email: plribeiro3000@gmail.com
|
38
38
|
executables: []
|