Class: Humanize::Bytes
- Inherits:
-
Object
show all
- Defined in:
- lib/humanize/bytes.rb
Constant Summary
collapse
- VERSION =
'2.2.0'
Instance Method Summary
collapse
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(options = {})
size = options.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
|