Sha256: 22478c02e2696e4aef44ef707c69061f050aa73d84ef10a2fbb64e06574e2371

Contents?: true

Size: 627 Bytes

Versions: 10

Compression:

Stored size: 627 Bytes

Contents

module ActiveObject::Integer
  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

  def factorial
    return 1 if zero?

    2.upto(self).inject(1) { |acc, elem| acc * elem }
  end

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

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

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

  def time
    Time.at(self)
  end

end

Integer.include(ActiveObject::Integer) if ActiveObject::Settings.config.autoload_integer

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
active_object-4.0.14 lib/active_object/integer.rb
active_object-4.0.13 lib/active_object/integer.rb
active_object-4.0.12 lib/active_object/integer.rb
active_object-4.0.11 lib/active_object/integer.rb
active_object-4.0.10 lib/active_object/integer.rb
active_object-4.0.9 lib/active_object/integer.rb
active_object-4.0.8 lib/active_object/integer.rb
active_object-4.0.7 lib/active_object/integer.rb
active_object-4.0.6 lib/active_object/integer.rb
active_object-4.0.5 lib/active_object/integer.rb