filesize 0.0.4 → 0.1.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/README.markdown +5 -0
- data/filesize.gemspec +1 -1
- data/lib/filesize.rb +4 -3
- metadata +1 -1
data/README.markdown
CHANGED
@@ -28,6 +28,11 @@ Filesize.from("12502343 B").to_s('GiB') # => "0.01 GiB"
|
|
28
28
|
Filesize.from("12502343 B").pretty # => "11.92 MiB"
|
29
29
|
```
|
30
30
|
|
31
|
+
### Comparing filesizes
|
32
|
+
```ruby
|
33
|
+
Filesize.from("1 KB") <=> Filesize.from("1 MB") # => -1
|
34
|
+
```
|
35
|
+
|
31
36
|
### Calculating with filesizes
|
32
37
|
#### The file size on the left side sets the type
|
33
38
|
```ruby
|
data/filesize.gemspec
CHANGED
data/lib/filesize.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
class Filesize
|
2
|
+
include Comparable
|
3
|
+
|
2
4
|
TYPE_PREFIXES = {
|
3
5
|
# Unit prefixes used for SI file sizes.
|
4
6
|
SI: %w{k M G T P E Z Y},
|
@@ -107,9 +109,8 @@ class Filesize
|
|
107
109
|
end
|
108
110
|
end
|
109
111
|
|
110
|
-
|
111
|
-
|
112
|
-
other.is_a?(self.class) && other.to_i == self.to_i
|
112
|
+
def <=>(other)
|
113
|
+
self.to_i <=> other.to_i
|
113
114
|
end
|
114
115
|
|
115
116
|
# @return [Array<self, other>]
|