Class: Humanize::Bytes
- Inherits:
-
Object
- Object
- Humanize::Bytes
- Defined in:
- lib/humanize/bytes.rb
Constant Summary collapse
- VERSION =
'2.1.0'
Instance Method Summary collapse
-
#initialize(value) ⇒ Bytes
constructor
A new instance of Bytes.
- #to_s(options = {}) ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(value) ⇒ Bytes
Returns a new instance of Bytes.
5 6 7 |
# File 'lib/humanize/bytes.rb', line 5 def initialize(value) @value = value.to_f end |
Instance Method Details
#to_s(options = {}) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/humanize/bytes.rb', line 13 def to_s( = {}) size = .fetch(:decimal_digits, nil) size ||= value.to_s.split('.').size == 1 ? 0 : value.to_s.split('.').last.size size = 0 if value.to_s.split('.').size >= 2 and value.to_s.split('.').last.to_s == '0' ("%.#{size}f" % value).to_s end |
#value ⇒ Object
9 10 11 |
# File 'lib/humanize/bytes.rb', line 9 def value @value end |