Class: Numeric
- Defined in:
- activesupport/lib/active_support/core_ext/object/blank.rb,
activesupport/lib/active_support/core_ext/object/json.rb,
activesupport/lib/active_support/core_ext/numeric/time.rb,
activesupport/lib/active_support/core_ext/numeric/bytes.rb,
activesupport/lib/active_support/core_ext/string/output_safety.rb
Overview
:nodoc:
Direct Known Subclasses
Constant Summary collapse
- KILOBYTE =
1024
- MEGABYTE =
KILOBYTE * 1024
- GIGABYTE =
MEGABYTE * 1024
- TERABYTE =
GIGABYTE * 1024
- PETABYTE =
TERABYTE * 1024
- EXABYTE =
PETABYTE * 1024
- ZETTABYTE =
EXABYTE * 1024
Instance Method Summary collapse
-
#as_json(options = nil) ⇒ Object
:nodoc:.
-
#blank? ⇒ false
No number is blank:.
-
#bytes ⇒ Object
(also: #byte)
Enables the use of byte calculations and declarations, like 45.bytes + 2.6.megabytes.
-
#days ⇒ Object
(also: #day)
Returns a Duration instance matching the number of days provided.
-
#exabytes ⇒ Object
(also: #exabyte)
Returns the number of bytes equivalent to the exabytes provided.
-
#fortnights ⇒ Object
(also: #fortnight)
Returns a Duration instance matching the number of fortnights provided.
-
#gigabytes ⇒ Object
(also: #gigabyte)
Returns the number of bytes equivalent to the gigabytes provided.
-
#hours ⇒ Object
(also: #hour)
Returns a Duration instance matching the number of hours provided.
- #html_safe? ⇒ Boolean
-
#in_milliseconds ⇒ Object
Returns the number of milliseconds equivalent to the seconds provided.
-
#kilobytes ⇒ Object
(also: #kilobyte)
Returns the number of bytes equivalent to the kilobytes provided.
-
#megabytes ⇒ Object
(also: #megabyte)
Returns the number of bytes equivalent to the megabytes provided.
-
#minutes ⇒ Object
(also: #minute)
Returns a Duration instance matching the number of minutes provided.
-
#petabytes ⇒ Object
(also: #petabyte)
Returns the number of bytes equivalent to the petabytes provided.
- #present? ⇒ Boolean
-
#seconds ⇒ Object
(also: #second)
Returns a Duration instance matching the number of seconds provided.
-
#terabytes ⇒ Object
(also: #terabyte)
Returns the number of bytes equivalent to the terabytes provided.
-
#weeks ⇒ Object
(also: #week)
Returns a Duration instance matching the number of weeks provided.
-
#zettabytes ⇒ Object
(also: #zettabyte)
Returns the number of bytes equivalent to the zettabytes provided.
Instance Method Details
#as_json(options = nil) ⇒ Object
:nodoc:
111 112 113 |
# File 'activesupport/lib/active_support/core_ext/object/json.rb', line 111 def as_json( = nil) # :nodoc: self end |
#blank? ⇒ false
No number is blank:
1.blank? # => false
0.blank? # => false
177 178 179 |
# File 'activesupport/lib/active_support/core_ext/object/blank.rb', line 177 def blank? false end |
#bytes ⇒ Object Also known as: byte
Enables the use of byte calculations and declarations, like 45.bytes + 2.6.megabytes
2.bytes # => 2
15 16 17 |
# File 'activesupport/lib/active_support/core_ext/numeric/bytes.rb', line 15 def bytes self end |
#days ⇒ Object Also known as: day
Returns a Duration instance matching the number of days provided.
2.days # => 2 days
37 38 39 |
# File 'activesupport/lib/active_support/core_ext/numeric/time.rb', line 37 def days ActiveSupport::Duration.days(self) end |
#exabytes ⇒ Object Also known as: exabyte
Returns the number of bytes equivalent to the exabytes provided.
2.exabytes # => 2_305_843_009_213_693_952
63 64 65 |
# File 'activesupport/lib/active_support/core_ext/numeric/bytes.rb', line 63 def exabytes self * EXABYTE end |
#fortnights ⇒ Object Also known as: fortnight
Returns a Duration instance matching the number of fortnights provided.
2.fortnights # => 4 weeks
53 54 55 |
# File 'activesupport/lib/active_support/core_ext/numeric/time.rb', line 53 def fortnights ActiveSupport::Duration.weeks(self * 2) end |
#gigabytes ⇒ Object Also known as: gigabyte
Returns the number of bytes equivalent to the gigabytes provided.
2.gigabytes # => 2_147_483_648
39 40 41 |
# File 'activesupport/lib/active_support/core_ext/numeric/bytes.rb', line 39 def gigabytes self * GIGABYTE end |
#hours ⇒ Object Also known as: hour
Returns a Duration instance matching the number of hours provided.
2.hours # => 2 hours
29 30 31 |
# File 'activesupport/lib/active_support/core_ext/numeric/time.rb', line 29 def hours ActiveSupport::Duration.hours(self) end |
#html_safe? ⇒ Boolean
13 14 15 |
# File 'activesupport/lib/active_support/core_ext/string/output_safety.rb', line 13 def html_safe? true end |
#in_milliseconds ⇒ Object
Returns the number of milliseconds equivalent to the seconds provided. Used with the standard time durations.
2.in_milliseconds # => 2000
1.hour.in_milliseconds # => 3600000
63 64 65 |
# File 'activesupport/lib/active_support/core_ext/numeric/time.rb', line 63 def in_milliseconds self * 1000 end |
#kilobytes ⇒ Object Also known as: kilobyte
Returns the number of bytes equivalent to the kilobytes provided.
2.kilobytes # => 2048
23 24 25 |
# File 'activesupport/lib/active_support/core_ext/numeric/bytes.rb', line 23 def kilobytes self * KILOBYTE end |
#megabytes ⇒ Object Also known as: megabyte
Returns the number of bytes equivalent to the megabytes provided.
2.megabytes # => 2_097_152
31 32 33 |
# File 'activesupport/lib/active_support/core_ext/numeric/bytes.rb', line 31 def megabytes self * MEGABYTE end |
#minutes ⇒ Object Also known as: minute
Returns a Duration instance matching the number of minutes provided.
2.minutes # => 2 minutes
21 22 23 |
# File 'activesupport/lib/active_support/core_ext/numeric/time.rb', line 21 def minutes ActiveSupport::Duration.minutes(self) end |
#petabytes ⇒ Object Also known as: petabyte
Returns the number of bytes equivalent to the petabytes provided.
2.petabytes # => 2_251_799_813_685_248
55 56 57 |
# File 'activesupport/lib/active_support/core_ext/numeric/bytes.rb', line 55 def petabytes self * PETABYTE end |
#present? ⇒ Boolean
181 182 183 |
# File 'activesupport/lib/active_support/core_ext/object/blank.rb', line 181 def present? true end |
#seconds ⇒ Object Also known as: second
Returns a Duration instance matching the number of seconds provided.
2.seconds # => 2 seconds
13 14 15 |
# File 'activesupport/lib/active_support/core_ext/numeric/time.rb', line 13 def seconds ActiveSupport::Duration.seconds(self) end |
#terabytes ⇒ Object Also known as: terabyte
Returns the number of bytes equivalent to the terabytes provided.
2.terabytes # => 2_199_023_255_552
47 48 49 |
# File 'activesupport/lib/active_support/core_ext/numeric/bytes.rb', line 47 def terabytes self * TERABYTE end |
#weeks ⇒ Object Also known as: week
Returns a Duration instance matching the number of weeks provided.
2.weeks # => 2 weeks
45 46 47 |
# File 'activesupport/lib/active_support/core_ext/numeric/time.rb', line 45 def weeks ActiveSupport::Duration.weeks(self) end |