Class: Ilp::Term

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-cbc/ilp/term.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(var, mult = 1) ⇒ Term

Returns a new instance of Term.



5
6
7
8
# File 'lib/ruby-cbc/ilp/term.rb', line 5

def initialize(var, mult = 1)
  @mult = mult
  @var = var
end

Instance Attribute Details

#multObject

Returns the value of attribute mult.



3
4
5
# File 'lib/ruby-cbc/ilp/term.rb', line 3

def mult
  @mult
end

#varObject

Returns the value of attribute var.



3
4
5
# File 'lib/ruby-cbc/ilp/term.rb', line 3

def var
  @var
end

Instance Method Details

#*(other) ⇒ Object

Raises:

  • (ArgumentError)


30
31
32
33
# File 'lib/ruby-cbc/ilp/term.rb', line 30

def *(other)
  raise ArgumentError, "Argument is not numeric" unless other.is_a? Numeric
  Ilp::Term.new(@var, @mult * other)
end

#+(other) ⇒ Object



10
11
12
# File 'lib/ruby-cbc/ilp/term.rb', line 10

def +(other)
  Ilp::TermArray.new([self]) + other
end

#-(other) ⇒ Object



14
15
16
# File 'lib/ruby-cbc/ilp/term.rb', line 14

def -(other)
  Ilp::TermArray.new([self]) - other
end

#<=(other) ⇒ Object



22
23
24
# File 'lib/ruby-cbc/ilp/term.rb', line 22

def <=(other)
  Ilp::TermArray.new([self]) <= other
end

#==(other) ⇒ Object



18
19
20
# File 'lib/ruby-cbc/ilp/term.rb', line 18

def ==(other)
  Ilp::TermArray.new([self]) == other
end

#>=(other) ⇒ Object



26
27
28
# File 'lib/ruby-cbc/ilp/term.rb', line 26

def >=(other)
  Ilp::TermArray.new([self]) >= other
end

#coerce(num) ⇒ Object



35
36
37
# File 'lib/ruby-cbc/ilp/term.rb', line 35

def coerce(num)
  [Ilp::Constant.new(num), Ilp::TermArray.new([self])]
end

#to_sObject



39
40
41
42
43
# File 'lib/ruby-cbc/ilp/term.rb', line 39

def to_s
  str = "++-"[mult <=> 0] << " "
  str << mult.abs.to_s << " " if mult != 1
  str << var.to_s
end