Class: Humanize::Byte
- Inherits:
-
Object
- Object
- Humanize::Byte
- Defined in:
- lib/humanize/byte.rb
Instance Method Summary collapse
-
#initialize(value) ⇒ Byte
constructor
A new instance of Byte.
- #to_b ⇒ Object
- #to_g ⇒ Object
- #to_k ⇒ Object
- #to_m ⇒ Object
- #to_s(options = {}) ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(value) ⇒ Byte
Returns a new instance of Byte.
3 4 5 |
# File 'lib/humanize/byte.rb', line 3 def initialize(value) @value = value end |
Instance Method Details
#to_b ⇒ Object
11 12 13 |
# File 'lib/humanize/byte.rb', line 11 def to_b self end |
#to_g ⇒ Object
23 24 25 |
# File 'lib/humanize/byte.rb', line 23 def to_g Giga.new @value / 1024.0 / 1024 / 1024 end |
#to_k ⇒ Object
15 16 17 |
# File 'lib/humanize/byte.rb', line 15 def to_k Kilo.new @value / 1024.0 end |
#to_m ⇒ Object
19 20 21 |
# File 'lib/humanize/byte.rb', line 19 def to_m Mega.new @value / 1024.0 / 1024 end |
#to_s(options = {}) ⇒ Object
27 28 29 30 31 |
# File 'lib/humanize/byte.rb', line 27 def to_s( = {}) size = .fetch(:decimal_digits, nil) size ||= value.to_s.split('.').size == 1 ? 0 : value.to_s.split('.').last.size ("%.#{size}f" % value).to_s end |
#value ⇒ Object
7 8 9 |
# File 'lib/humanize/byte.rb', line 7 def value @value end |