class CiteProc::Number

A CiteProc Variable used for numeric values.

Constants

FACTORS
MAX_ROMAN

Public Class Methods

pluralize?(string) click to toggle source
# File lib/citeproc/number.rb, line 16
def pluralize?(string)
  /\S[\s,&–-]\S|\df/ === string
end
romanize(number) click to toggle source

@param number [#to_i] the number to convert @return [String] roman equivalent of the passed-in number

# File lib/citeproc/number.rb, line 22
def romanize(number)
  number, roman = number.to_i, ''

  return number unless number > 0 || number < MAX_ROMAN

  FACTORS.each do |code, factor|
    count, number = number.divmod(factor)
    roman << (code * count)
  end

  roman
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/citeproc/number.rb, line 36
def <=>(other)
  case
  when other.nil?
    1
  when numeric?
    if other.respond_to?(:to_i)
      to_i <=> other.to_i
    else
      nil
    end
  when other.is_a?(Variable) || other.is_a?(String)
    to_s <=> other.to_s
  else
    nil
  end
end