human_size_to_number 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md ADDED
@@ -0,0 +1,30 @@
1
+ 1.0.1
2
+ -----
3
+
4
+ - Fixed when passing '1 Byte'
5
+
6
+ 1.0.0
7
+ -----
8
+
9
+ - Upgraded compatibility with rubies.
10
+
11
+ 0.3.0
12
+ -----
13
+
14
+ - Removed activesupport dependencie
15
+ - Updated README.md
16
+
17
+ 0.2.0
18
+ -----
19
+
20
+ - Fixed returned value in order to have Integer instead of Float
21
+
22
+ 0.1.0
23
+ -----
24
+
25
+ - Implemented human\_size\_to\_number into String class instead of ActionView::Helpers::TextHelper
26
+
27
+ 0.0.1
28
+ -----
29
+
30
+ - Initial release
data/README.md CHANGED
@@ -9,12 +9,18 @@ This gem implement the missing reverse of the [ActionView::Helpers::NumberHelper
9
9
  Usage
10
10
  -----
11
11
 
12
- > "123 Bytes".human_size_to_number # => 123
13
- > "1.12 KB".human_size_to_number # => 1239
14
- > "12.1 KB".human_size_to_number # => 12390
15
- > "1.18 MB".human_size_to_number # => 1237320
16
- > "1.15 GB".human_size_to_number # => 1234803098
17
- > "1.12 TB".human_size_to_number # => 1231453023109
12
+ > "0 Bytes".human_size_to_number # => 0
13
+ > "123 Bytes".human_size_to_number # => 123
14
+ > "1.12 KB".human_size_to_number # => 1239
15
+ > "12.1 KB".human_size_to_number # => 12390
16
+ > "1.18 MB".human_size_to_number # => 1237320
17
+ > "1.15 GB".human_size_to_number # => 1234803098
18
+ > "1.12 TB".human_size_to_number # => 1231453023109
19
+ > "lorem".human_size_to_number # => nil
20
+ > "lorem".human_size_to_number(:raise => true) # => String::InvalidSizeStringError: String::InvalidSizeStringError
21
+ from ./lib/human_size_to_number/helper.rb:18:in `human_size_to_number'
22
+ from (irb):3
23
+ from :0
18
24
 
19
25
  Project Tracking
20
26
  ----------------
@@ -10,7 +10,7 @@ class String
10
10
  end
11
11
 
12
12
  def human_size_to_number(options={})
13
- size, unit = self.scan(/(\d*\.?\d+)\s?(Bytes|KB|MB|GB|TB)/).first
13
+ size, unit = self.scan(/(\d*\.?\d+)\s?(Bytes?|KB|MB|GB|TB)/).first
14
14
  number = begin
15
15
  Float(size)
16
16
  rescue ArgumentError, TypeError
@@ -21,7 +21,7 @@ class String
21
21
  end
22
22
  end
23
23
  number = case unit
24
- when "Bytes"
24
+ when "Byte", "Bytes"
25
25
  number
26
26
  when "KB"
27
27
  number * 1024
@@ -1,3 +1,3 @@
1
1
  module HumanSizeToNumber
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -19,6 +19,16 @@ describe String do
19
19
  end
20
20
  end
21
21
  end
22
+ context "when passing the string 0 Bytes" do
23
+ it "should return the number 0" do
24
+ "0 Bytes".human_size_to_number.should == 0
25
+ end
26
+ end
27
+ context "when passing the string 1 Byte" do
28
+ it "should return the number 1" do
29
+ "1 Byte".human_size_to_number.should == 1
30
+ end
31
+ end
22
32
  context "when passing the string 123 Bytes" do
23
33
  it "should return the number 123" do
24
34
  "123 Bytes".human_size_to_number.should == 123
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: human_size_to_number
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 0
10
- version: 1.0.0
9
+ - 1
10
+ version: 1.0.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - zedtux
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-09-04 00:00:00 Z
18
+ date: 2011-09-30 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rake
@@ -73,6 +73,7 @@ files:
73
73
  - .rspec
74
74
  - .rvmrc
75
75
  - .travis.yml
76
+ - CHANGELOG.md
76
77
  - Gemfile
77
78
  - README.md
78
79
  - Rakefile