Sha256: edfed00985c0e448450b2ba82dfdd21d811dfe0fcbe15302bae26033e1ebb9fa

Contents?: true

Size: 611 Bytes

Versions: 9

Compression:

Stored size: 611 Bytes

Contents

class 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) { |p, n| p * n }
  end

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

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

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

  def time
    Time.at(self)
  end

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
active_object-2.5.2 lib/active_object/integer.rb
active_object-2.5.1 lib/active_object/integer.rb
active_object-2.5.0 lib/active_object/integer.rb
active_object-2.4.0 lib/active_object/integer.rb
active_object-2.3.4 lib/active_object/integer.rb
active_object-2.3.3 lib/active_object/integer.rb
active_object-2.3.2 lib/active_object/integer.rb
active_object-2.3.1 lib/active_object/integer.rb
active_object-2.3.0 lib/active_object/integer.rb