Module: Quicopt::Format Private

Defined in:
lib/quicopt/model.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Number and term rendering shared by the DSL's to_s methods. Presentation only — nothing here touches the wire.

Class Method Summary collapse

Class Method Details

.number(value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

A float without its trailing .0 when it is whole.



40
41
42
43
44
# File 'lib/quicopt/model.rb', line 40

def number(value)
  return value.to_s unless value.finite?

  value == value.to_i ? value.to_i.to_s : value.to_s
end

.term(coefficient, factors) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

One term, dropping a unit coefficient (+x+, -x, 3*x).



47
48
49
50
51
52
# File 'lib/quicopt/model.rb', line 47

def term(coefficient, factors)
  return factors if coefficient == 1.0
  return "-#{factors}" if coefficient == -1.0

  "#{number(coefficient)}*#{factors}"
end