Class: Numeric
- Defined in:
- lib/muflax/num.rb,
lib/muflax/time.rb,
lib/muflax/blank.rb,
lib/muflax/deep_dup.rb
Overview
Copyright Freya Dorn <[email protected]>, 2017 License: GNU APGLv3 (or later) <www.gnu.org/copyleft/gpl.html>
Constant Summary collapse
- DELIMITER_REGEX =
/(\d)(?=(\d\d\d)+(?!\d))/
Instance Method Summary collapse
- #blank? ⇒ Boolean
- #days ⇒ Object (also: #day)
- #delimit(delimiter = "_") ⇒ Object
- #factorial ⇒ Object
- #factors ⇒ Object
- #fortnights ⇒ Object (also: #fortnight)
- #hours ⇒ Object (also: #hour)
- #milliseconds ⇒ Object (also: #millisecond)
- #minutes ⇒ Object (also: #minute)
- #months ⇒ Object (also: #month)
- #multiple_of?(number) ⇒ Boolean
- #prime? ⇒ Boolean
- #round_into(num) ⇒ Object
- #round_to(num) ⇒ Object
- #seconds ⇒ Object (also: #second)
- #weeks ⇒ Object (also: #week)
- #years ⇒ Object (also: #year)
Instance Method Details
#blank? ⇒ Boolean
16 |
# File 'lib/muflax/blank.rb', line 16 def blank? ; false ; end |
#days ⇒ Object Also known as: day
11 |
# File 'lib/muflax/time.rb', line 11 def days ; self.hours * 24 ; end |
#delimit(delimiter = "_") ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/muflax/num.rb', line 21 def delimit delimiter="_" left, right = self.to_s.split(".") left.gsub!(DELIMITER_REGEX) do |digit_to_delimit| "#{digit_to_delimit}#{delimiter}" end [left, right].compact.join(".") end |
#factorial ⇒ Object
36 37 38 |
# File 'lib/muflax/num.rb', line 36 def factorial Math.factorial self end |
#factors ⇒ Object
40 41 42 |
# File 'lib/muflax/num.rb', line 40 def factors (1..self).select{|f| self.multiple_of? f} end |
#fortnights ⇒ Object Also known as: fortnight
13 |
# File 'lib/muflax/time.rb', line 13 def fortnights ; self.weeks * 2 ; end |
#hours ⇒ Object Also known as: hour
10 |
# File 'lib/muflax/time.rb', line 10 def hours ; self.minutes * 60 ; end |
#milliseconds ⇒ Object Also known as: millisecond
7 |
# File 'lib/muflax/time.rb', line 7 def milliseconds ; self.seconds / 1000.0 ; end |
#minutes ⇒ Object Also known as: minute
9 |
# File 'lib/muflax/time.rb', line 9 def minutes ; self.seconds * 60 ; end |
#months ⇒ Object Also known as: month
14 |
# File 'lib/muflax/time.rb', line 14 def months ; self.days * 30 ; end |
#multiple_of?(number) ⇒ Boolean
15 16 17 |
# File 'lib/muflax/num.rb', line 15 def multiple_of?(number) number != 0 ? self % number == 0 : zero? end |
#prime? ⇒ Boolean
30 31 32 33 34 |
# File 'lib/muflax/num.rb', line 30 def prime? return false if self < 2 not (2..(Math.sqrt(self))).any?{|f| self.multiple_of? f} end |
#round_into(num) ⇒ Object
7 8 9 |
# File 'lib/muflax/num.rb', line 7 def round_into num ((self / num) / num + 1) * num end |
#round_to(num) ⇒ Object
11 12 13 |
# File 'lib/muflax/num.rb', line 11 def round_to num (self / num.to_f).round * num end |
#seconds ⇒ Object Also known as: second
8 |
# File 'lib/muflax/time.rb', line 8 def seconds ; self ; end |
#weeks ⇒ Object Also known as: week
12 |
# File 'lib/muflax/time.rb', line 12 def weeks ; self.days * 7 ; end |
#years ⇒ Object Also known as: year
15 |
# File 'lib/muflax/time.rb', line 15 def years ; self.days * 365 ; end |