Module: ActiveObject::Integer

Defined in:
lib/active_object/integer.rb

Constant Summary collapse

ROMAN_VALUES =
{
  M: 1000, CM: 900, D: 500, CD: 400, C: 100, XC: 90, L: 50, XL: 40, X: 10, IX: 9, V: 5, IV: 4,
  I: 1
}.freeze

Instance Method Summary collapse

Instance Method Details

#factorialObject



7
8
9
10
# File 'lib/active_object/integer.rb', line 7

def factorial
  return(1) if zero?
  2.upto(self).inject(1) { |a, e| a * e }
end

#of(&block) ⇒ Object



12
13
14
# File 'lib/active_object/integer.rb', line 12

def of(&block)
  Array.new(self, &block)
end

#romanObject



16
17
18
19
20
21
# File 'lib/active_object/integer.rb', line 16

def roman
  return('') if zero?
  return("-#{(-self).roman}") if negative?

  ROMAN_VALUES.each { |key, val| return("#{key}#{(self - val).roman}") if val <= self }
end

#timeObject



23
24
25
# File 'lib/active_object/integer.rb', line 23

def time
  Time.at(self)
end