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 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
- TODO: Write a gem description
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
- TODO: Write usage instructions here
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
@@ -1,2 +1,8 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
+ require "rspec/core/rake_task"
4
+
5
+ RSpec::Core::RakeTask.new
6
+
7
+ desc "Default Task"
8
+ task :default => [ :spec ]
@@ -9,6 +9,10 @@ module Humanize
9
9
  @value
10
10
  end
11
11
 
12
+ def to_b
13
+ value
14
+ end
15
+
12
16
  def to_k
13
17
  @value / 1024.0
14
18
  end
@@ -21,6 +21,10 @@ module Humanize
21
21
  @value * 1024
22
22
  end
23
23
 
24
+ def to_g
25
+ @value
26
+ end
27
+
24
28
  def to_s
25
29
  @value.instance_of?(Float) ? formatted_float + ' giga bytes' : @value.to_s + ' giga bytes'
26
30
  end
@@ -13,6 +13,10 @@ module Humanize
13
13
  @value * 1024
14
14
  end
15
15
 
16
+ def to_k
17
+ @value
18
+ end
19
+
16
20
  def to_m
17
21
  @value / 1024.0
18
22
  end
@@ -17,6 +17,10 @@ module Humanize
17
17
  @value * 1024
18
18
  end
19
19
 
20
+ def to_m
21
+ @value
22
+ end
23
+
20
24
  def to_g
21
25
  @value / 1024.0
22
26
  end
@@ -1,5 +1,5 @@
1
1
  module Humanize
2
2
  module Bytes
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -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
@@ -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('1024').should be_instance_of(Humanize::Bytes::Byte)
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('1024', 'k').should be_instance_of(Humanize::Bytes::Kilo)
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('1024', 'm').should be_instance_of(Humanize::Bytes::Mega)
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('1024', 'g').should be_instance_of(Humanize::Bytes::Giga)
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.1
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-02 00:00:00.000000000 Z
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: &16545640 !ruby/object:Gem::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: *16545640
24
+ version_requirements: *15077160
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &16561300 !ruby/object:Gem::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: *16561300
35
+ version_requirements: *15092840
36
36
  description: Convert Byte, Kbyte, MByte, Gbyte into each other
37
37
  email: plribeiro3000@gmail.com
38
38
  executables: []