Sha256: cb19f40c5e914b01756d6ccff85a48579bf17a0711653f1d1a0d36ccd70e371b

Contents?: true

Size: 711 Bytes

Versions: 20

Compression:

Stored size: 711 Bytes

Contents

# frozen_string_literal: true

module ActiveObject
  module 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
end

Integer.include(ActiveObject::Integer) if ActiveObject.configuration.autoload_integer

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
active_object-5.7.0 lib/active_object/integer.rb
active_object-5.6.0 lib/active_object/integer.rb
active_object-5.5.3 lib/active_object/integer.rb
active_object-5.5.2 lib/active_object/integer.rb
active_object-5.5.1 lib/active_object/integer.rb
active_object-5.5.0 lib/active_object/integer.rb
active_object-5.4.0 lib/active_object/integer.rb
active_object-5.3.1 lib/active_object/integer.rb
active_object-5.3.0 lib/active_object/integer.rb
active_object-5.2.5 lib/active_object/integer.rb
active_object-5.2.4 lib/active_object/integer.rb
active_object-5.2.3 lib/active_object/integer.rb
active_object-5.2.2 lib/active_object/integer.rb
active_object-5.2.1 lib/active_object/integer.rb
active_object-5.2.0 lib/active_object/integer.rb
active_object-5.1.2 lib/active_object/integer.rb
active_object-5.1.1 lib/active_object/integer.rb
active_object-5.1.0 lib/active_object/integer.rb
active_object-5.0.2 lib/active_object/integer.rb
active_object-5.0.1 lib/active_object/integer.rb